我有命名路由器出口和延迟加载模块的问题。我有 2 个路由器插座,第一个没有名字,第二个名为mainapp。
app.component.html
<router-outlet></router-outlet>
app.main.component.html
<router-outlet name="mainapp"></router-outlet>
应用程序.routes.ts
export const routes: Routes = [
{path: 'login', component: LoginComponent},
{path: 'app', component: AppMainComponent, children:[
{path: '', loadChildren: 'app/client/client.module#ClientModule'}
]}
];
客户端.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 被加载到路由器出口
- 登录后 AppMainComponent 被加载到路由器出口
- 现在我尝试将 ClientComponent 加载到命名路由器插座mainapp
我收到错误
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" }
]}
];