问题
I want to route to "config" router, which is nested 2 outlets deep but I'm unable to figure out the correct way to do so.
<router>
<router name="main">
<router name="config">
</router>
</router>
</router>
In my routing.ts, I created 2 ways to reach the component:
export const routes: Routes = [
{
// Entrypoint.
path: 'Foo', component: FooComponent, canActivate: [IsServerOnlineGuard], children: [
path: 'Bar', component: BarComponent, outlet: 'main', children: [
{ path: 'Smtp', component: smtpComponent, outlet: 'config' } // registered as a child
],
path: 'Smtp', component: smtpComponent, outlet: 'config' }, // registered under the "main" component
},
]
},
{ path: '', pathMatch: 'full', redirectTo: 'CSI' },
{ path: '**', redirectTo: 'CSI' },
];
I tried navigating there in 2 ways.
public RouteToConfigOutlet(componentName: string) {
this._router.navigate([`/(main:BarComponent)/`, {
outlets: {
config: ['Smtp']
}
}]);
}
public RouteToConfigOutlet(componentName: string) {
this._router.navigate([``, {
outlets: {
main: ['BarComponent'],
config: ['Smtp']
}
}]);
}
Alas I'm unable to get my component to show up and am trying to find the correct way to get there.
回答1:
I found the answer on this website. The correct way of routing is:
router.navigate(
[{
outlets: {
'main': ['BarComponent',
{ outlets: { 'config': ['smtpComponent'] } } ]
}
}]);
来源:https://stackoverflow.com/questions/58381534/show-component-in-nested-router