I have a root app component with a router-outlet, and the routes are loaded from a home module routes which uses lazy loading with loadchildren in its children routes. There is a router-outlet in the home component and also there is router-outlets in all the child modules of the home which are lazyloaded. The routes are working fine but the child routes are also getting loaded in root router-outlet. Eg:- the component 'testCreateComponent' is loading with localhost:4200/test/create and also localhost:4200/create.
Sample code levels are as follows:-
app.component.html
<div>app</div>
<router-outlet></router-outlet>
app-routing.module.ts
export const APP_ROUTES: Routes = [
{path: '**', redirectTo: '', pathMatch: 'full'}
];
home.component.html
<div>home</div>
<router-outlet><router-outlet>
home-routing.module.ts
const routes: Routes = [{
path: '',
component: HomeComponent,
canActivate: [LoggedUserGuard],
canActivateChild: [AuthGuard],
children: [
{path: '', redirectTo: 'dashboard', pathMatch: 'full'},
{
path: 'test',
loadChildren: () => testModule
},
{
path: 'dashboard',
component: DashboardComponent,
data: {
breadcrumb: 'Dashboard'
}
},
{
path: 'dummy',
loadChildren: () => dummyModule,
}
]
}];
testComponent.html
<div>Test</test>
<router-outlet></router-outlet>
test-routing.module.ts
const routes: Routes = [{
path: '',
component: TestComponent,
children: [
{path: '', component: ListComponent,
data: {
breadcrumb: 'List'
}},
{path: 'create', component: testCreateComponent},
{ path: 'detail/:id',
component: TestEditComponent,
}
]
}];