简体   繁体   English

Angular 路由和子路由管理

[英]Angular route and child route management

Somebody can tell me if is possible to open a child route in a new view instead of opening right under it?有人可以告诉我是否可以在新视图中打开子路线而不是在其下方打开? If so how and how to comeback to the father route previous state of navigation?如果是这样,如何以及如何恢复到之前的 state 的导航?

Instead of代替

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

Do:做:

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

It's good to use children , because if you want to use some guard s it's gonna work for all children routes, it's very useful when you're creating authenticated routes.使用children很好,因为如果您想使用一些guard ,它将适用于所有子路由,当您创建经过身份验证的路由时它非常有用。

Example:例子:

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 },
        ]
      }
    ],
  }
];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM