I have a DashboardComponent that is being loaded if the router is at /client and the same for /product:
export const routes: Routes =
[
{ path: '', component: HomeComponent },
{ path: 'client', component: DashboardComponent },
{ path: 'product', component: DashboardComponent }
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class RoutesModule { }
And I then load the different components in like this (in dashboard.component.ts):
this.router.events.subscribe(path => {
if (this.router.url == "/client") {
this.isClient = true;
}
if (this.router.url != "/client") {
this.isClient = false;
}
if (this.router.url == "/product") {
this.isProduct = true;
}
if (this.router.url != "/product") {
this.isProduct = false;
}
});
Then in the dashboard.component.html I do:
<app-client *ngIf="isClient"></app-client>
<app-product *ngIf="isProduct"></app-product>
I feel like this is not the way to do it but I cannot find a good explanation on how to implement that if you go to e.g. /dashboard/client it loads the ClientComponent inside of the DashboardComponent and the same for ProductComponent