I have problem with named router outlet and lazy loading module. I have 2 router outlets first without name and second is named mainapp.
app.component.html
<router-outlet></router-outlet>
app.main.component.html
<router-outlet name="mainapp"></router-outlet>
app.routes.ts
export const routes: Routes = [
{path: 'login', component: LoginComponent},
{path: 'app', component: AppMainComponent, children:[
{path: '', loadChildren: 'app/client/client.module#ClientModule'}
]}
];
client.module.ts
@NgModule({
imports: [
SharedModule,
RouterModule.forChild([
{path: 'client', component: ClientListComponent, outlet: "mainapp" },
{path: 'client/:id', component: ClientComponent, outlet: "mainapp" }
])
],
declarations: [ClientListComponent, ClientComponent],
exports: [ClientListComponent, ClientComponent]
})
export class ClientModule { }
- LoginComponent is loaded into router outlet
- After login AppMainComponent is loaded into router outlet
- Now I try load ClientComponent to named router outlet mainapp
I get error
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'app'
Error: Cannot match any routes. URL Segment: 'app
When I modified routes to this it works:
export const routes: Routes = [
{path: 'login', component: LoginComponent},
{path: 'app', component: AppMainComponent, children:[
{path: 'client', component: ClientListComponent, outlet: "mainapp" },
{path: 'client/:id', component: ClientComponent, outlet: "mainapp" }
]}
];