我的命名路由器插座和延迟加载模块有问题。 我有2个路由器出口,没有名字,第二个被命名为 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 { }
我收到错误
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'app'
Error: Cannot match any routes. URL Segment: 'app
当我修改路线时,它可以工作:
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" }
]}
];