0

有人可以告诉我是否可以在新视图中打开子路线而不是在其下方打开?如果是这样,如何以及如何回到父路由之前的导航状态?

4

2 回答 2

0

代替

const routes: Routes = [
   { path: 'first', component: ExampleComponent, children: [
       { path: 'second', component: Example2Compoennt, }
   ] }
];

做:

const routes: Routes = [
   { path: 'first', component: ExampleComponent },
   { path: 'first/second', component: Example2Compoennt },
];

于 2020-05-06T11:50:14.943 回答
0

使用起来很好children,因为如果你想使用 some guards 它将适用于所有子路由,当你创建经过身份验证的路由时它非常有用。

例子:

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 },
        ]
      }
    ],
  }
];
于 2020-05-06T12:07:56.653 回答