3
votes

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 { }
  1. LoginComponent is loaded into router outlet
  2. After login AppMainComponent is loaded into router outlet
  3. 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" }
    ]}
];
1

1 Answers

1
votes

Seems to be known bug that you can follow at: https://github.com/angular/angular/issues/10981