I recently started working with Angular 5 and I'm encountering an issue with component routing.
My goal is to have the app display a login screen when a user first opens it (the login screen should take up the entire browser window). Once the user successfully logs in, they should be directed to the Home Component.
The Home component includes a Toolbar and Side menu bar. When a user selects an option from the side menu bar, I want to show the relevant component data in the content area of the Home component.
Currently, everything is functioning as expected - the login screen is displayed initially and upon successful validation, the Home page is shown to the user.
The problem arises when a user selects a menu item from the side menu bar - instead of displaying the respective component in the content area of the Home component, it opens as a separate component that takes up the full screen.
home.component.ts
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer class="sidenav" fixedInViewport="true" [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'" [opened]="!(isHandset$ | async)" style="background:black">
<mat-toolbar class="menuBar">Menus</mat-toolbar>
<mat-nav-list>
<a class="menuTextColor" mat-list-item routerLink="/settings">Link 1</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar class="toolbar">
<button class="menuTextColor" type="button" aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()"
*ngIf="isHandset$ | async">
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
<span class="toolbarHeading">Application Title</span>
</mat-toolbar>
//Content area ,need to show the components related to the side menu
</mat-sidenav-content>
</mat-sidenav-container>
app.components.ts
<router-outlet></router-outlet>
In app.component.ts, I have the
app.module.ts
const routings: Routes = [
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{ path: 'home', component: HomeComponent },
{ path: 'settings', component: SettingsComponent },
{ path: '**', redirectTo: '/login', pathMatch: 'full' },
];
where I have defined the routes.
Can someone assist me in resolving this issue?