在父母路由器插座内渲染子组件内容

时间:2017-01-25 14:45:51

标签: angular angular2-routing router-outlet

我在'父母'路由器插座中渲染子组件内容时遇到问题。

这是我的主要途径:

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(当前在路由器插座内部,称为合约子路由器插座)(我在代码中将其称为Wrapper Router Outlet)。

但是我不知道怎么做。我已经尝试过使用outlet属性了,但是这个帖子似乎有插座和延迟加载路径的问题 - Angular2 router - Auxiliary route并且我得到了与该问题中描述的相同的错误......

感谢先进的帮助!

更新

我注意到它可以通过稍微操纵路线看起来像这样:

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 }
               ]
            }]
    }];

所以,通过将这两条路线('person','person /:id')向上移动一级,它们会在'Wrapper router-outlet'中呈现,这就是我想要渲染它的地方,但是这个只是似乎没有正确的方法去做...那些路线应该是儿童路线,这样做会让他们与他们的父母兄弟姐妹......如果有人能指出我正确的方向,我会非常感激

0 个答案:

没有答案