Angular路由和子路由管理

问题描述 投票:0回答:1

谁能告诉我,是否可以在新视图中打开子航线,而不是在它的正下方打开? 如果可以,如何回到父航线之前的导航状态?

angular angular-router angular-routerlink angular-new-router
1个回答
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 },
];


0
投票

用的好 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 },
        ]
      }
    ],
  }
];
© www.soinside.com 2019 - 2024. All rights reserved.