我将root
路由定义为
const routes: Routes = [{
path: '',
component: HomeComponent
},
{
path: 'module1',
loadChildren: './module1/module1.module#Module1Module'
},
{
path: '**',
redirectTo: ''
}
];
有module1.routing.ts
:
const routes: Routes = [{
path: '',
component: SubModule1Component,
children: [{
path: 'mod1child1',
component: SubMod1Child1Component
},
{
path: 'mod1child2',
component: SubMod1Child2Component,
children: [{
path: '',
component: Outlet1Component,
outlet: 'outlet1'
},
{
path: 'newout1',
component: Outlet1NewComponent,
outlet: 'outlet1'
},
{
path: '',
component: Outlet2Component,
outlet: 'outlet2',
children: [{
path: 'childoutlet2',
component: ChildOutlet2Component,
outlet: 'outlet2'
}],
},
],
},
],
canActivate: [AuthGuardService],
}, ];
当我导航到/module1/mod1child2
以下位置时,此代码有效:
我上面图片的 HTML 页面是:
<h1>Child 2</h1>
<button [routerLink]="[{outlets: {'outlet1': ['newout1']}}]">Change Outlet 1</button>
<button [routerLink]="[{outlets: {'outlet2': ['childoutlet2']}}]">Change Outlet 2</button>
<div style="display: flex;">
<div style="display: grid ;border: 1px solid red; width: 50%;height: 100px;float:left">
<router-outlet name="outlet1"></router-outlet>
</div>
<div style="display: grid ;border: 1px solid green; width: 50%;height: 100px;float:left">
<router-outlet name="outlet2"></router-outlet>
</div>
</div>
我无法加载
{ path: 'childoutlet2', component: ChildOutlet2Component , outlet: 'outlet2'}
通过点击:
<button [routerLink]="[{outlets: {'outlet2': ['childoutlet2']}}]">Change Outlet 2</button>
我究竟做错了什么。我试过了
<button [routerLink]="['/module1/mod1child2',{outlets: {'outlet2': ['childoutlet2']}}]">
Change Outlet 2
</button>`
但这似乎也不起作用