谁能告诉我,是否可以在新视图中打开子航线,而不是在它的正下方打开? 如果可以,如何回到父航线之前的导航状态?
而不是
const routes: Routes = [
{ path: 'first', component: ExampleComponent, children: [
{ path: 'second', component: Example2Compoennt, }
] }
];
做。
const routes: Routes = [
{ path: 'first', component: ExampleComponent },
{ path: 'first/second', component: Example2Compoennt },
];
用的好 children
因为如果你想使用一些 guard
它适用于所有子路由,在创建认证路由时非常有用。
例如:
const routes: Routes = [
{
path: 'first',
children: [
{ path: '', component: FirstComponent },
{ path: 'second', component: SecondComponent },
{
path: 'third',
canActivate: [YourGuard],
children: [
{ path: '', component: ThirdComponent },
{ path: 'another-route', component: FourthComponent },
]
}
],
}
];