我在“父母”路由器插座内渲染子组件内容时遇到问题。
这是我的主要路线:
export const routes: Routes = [
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: 'login', redirectTo: 'login', pathMatch: 'full' },
{ path: 'notary', loadChildren: 'app/notary/notary.module#NotaryModule' }
]
其中“登录模块”是急切加载的,而我的“公证模块”是延迟加载的。
我的“公证模块”有自己的路线,即:
const routes: Routes = [
{
//<router-outlet> </router-outlet> i will call this one Wrapper router-oulet
path: 'contracts', component: ContractWrapperComponent, children: [
{ path: '', redirectTo: 'search', pathMatch:'full' },
{ path: 'search', component: ContractListComponent },
//<router-outlet> </router-outlet> i will call this one contract children router-outlet
{ path: ':id', component: ContractInsertUpdateComponent, children: [
{ path: 'persons', component: PersonListComponent },
{ path: 'person', component: PersonInsertEditComponent },
{ path: 'person/:id', component: PersonInsertEditComponent }]
}]
}];
我想(如果可能的话)在第一个路由器出口(我在代码中将其称为包装器路由器出口)中加载 PersonInsertEditComponent (当前在路由器出口内呈现,我称为合同子路由器出口)。
但是我不知道该怎么做。我尝试过使用插座属性,但这篇文章似乎存在插座和延迟加载路由的问题 - Angular2 路由器 - 辅助路由,我得到了与该问题中描述的相同的错误......
感谢您在高级的帮助!
更新
我注意到的是,它可以通过稍微操纵路线来完成,看起来像这样:
const routes: Routes = [
{
//<router-outlet> </router-outlet> i will call this one Wrapper router-oulet
path: 'contracts', component: ContractWrapperComponent, children: [
{ path: '', redirectTo: 'search', pathMatch:'full' },
{ path: 'search', component: ContractListComponent },
{ path: ':id/person', component: PersonInsertEditComponent },
{ path: ':id/person/:id', component: PersonInsertEditComponent }
//<router-outlet> </router-outlet> i will call this one contract children router-outlet
{ path: ':id', component: ContractInsertUpdateComponent, children: [
{ path: 'persons', component: PersonListComponent }
]
}]
}];
因此,通过将这 2 条路由('person'、'person/:id')上移一层,它们会在 'Wrapper router-outlet' 内呈现,这正是我希望它们被呈现的地方,但这只是没有似乎不是正确的方法...这些路线应该是子路线,这样做会使他们与父母成为兄弟姐妹...如果有人能指出我正确的方向,我将不胜感激。