【发布时间】:2018-10-03 16:23:47
【问题描述】:
我使用 Angular 6.1.9 及其路由器模块。我似乎不可能路由/显示命名的出口内容。
调用<a [routerLink]="['', { outlets: { editArea: ['addRootPartner'] } }]">foo</a> 时会崩溃:
NavigationError(id: 2, url: '/overview/work/allPartners(editArea:addRootPartner)', error: Error: 无法匹配任何路由。URL Segment: 'addRootPartner')
我的应用结构是:
app.module
app-routing.module
workspace.module
workspace-routing.module
应用路由:
const rootAppRoutes: Routes = [
{ path: '', redirectTo: 'overview', pathMatch: 'full' },
{ path: 'overview', loadChildren: './overview/workplace/workplace.module#WorkplaceModule' },
{ path: '**', component: PageNotFoundComponent }
];
重定向到加载workplace 模块的overview。
工作场所路由:
const workplaceRoutes: Routes = [
{ path: '', redirectTo: 'work', pathMatch: 'full'},
{ path: 'work', component: WorkplaceComponent, children: [
{ path: 'allPartners', component: RootPartnersComponent },
{ path: 'childPartners', component: ChildPartnersComponent },
{ path: '', redirectTo: 'allPartners', pathMatch: 'full'}
]},
{ path: 'addRootPartner', component: AddRootPartnerComponent, outlet: 'editArea' }
];
重定向到显示WorkplaceComponent 的work。然后它进一步到子allPartners,它显示RootPartnersComponent。
在代码中我使用了两个<router-outlet>s。一个在组件app 模块内:
<router-outlet></router-outlet>
第二个在workplace模块中,WorkplaceComponent:
<router-outlet></router-outlet>
<router-outlet name="editArea"></router-outlet>
这个设置有什么问题?嵌套命名插座的使用是否有技术限制?
【问题讨论】: