防止从延迟加载的模块直接访问路由

时间:2017-03-08 10:59:50

标签: angular angular2-routing

从我的一个模块(MasterModule)中,加载MasterComponent及其子路由。其中一条子路径延迟加载EquipmentSLModule

master-routing.module.ts

const routes: Routes = [
  {
    path: 'master', redirectTo: '/master/dashboard', pathMatch: 'full'
  },
  {
    path: 'master',
    component: MasterComponent,
    children: [
      {
        path: 'dashboard',
        component: DashboardComponent,
      },

      ...  // Other routes

      {
        path: 'SL',
        loadChildren: './../equipment/equipment-SL.module#EquipmentSLModule'
      }
    ]
  }
];

从这个子模块中,我添加了子路由:

设备-SL-routing.module.ts

const routes: Routes = [
  {
    path: 'toto',
    component: EquipmentComponent,
  },
];

然后,我可以成功访问我的路线master/SL/toto,但我也可以直接从网址转到/toto,它也能正常运行。 有没有办法阻止只访问/toto

1 个答案:

答案 0 :(得分:0)

如果您想无缘无故地阻止访问<>,只需将其从路由配置中移除,或者如果您想制定某些条件,请使用/toto

CanActivate
相关问题