2017-03-08 148 views
0

从我的模块之一(MasterModule),我加载MasterComponent及其子路由。其中一个子路由延迟加载我EquipmentSLModule防止从延迟加载的模块直接访问路由

主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成功,但我也可以直接从URL访问/toto,它也可以工作。 有没有办法阻止只访问/toto

回答

0

如果您想阻止对/toto的访问,请不要将其从您的路由配置中删除,或者如果您想要创建一些条件,请使用CanActivate

//equipment-SL-routing.module.ts 
const routes: Routes = [ 
    { 
    path: '', 
    component: EquipmentComponent, 
    }, 
]; 
+0

因为我需要从延迟加载的'主/ SL/toto'路线我无法删除它,因为它是限定从所述'设备-SL-routing.module.ts'路由。除CanActivate之外没有别的选择吗? –

+0

@AlexBeugnet查看更新 –

+0

它不会改变这个问题,我将能够达到''/主/ SL'(这是我想要的),但我也可以手动去''''哪个是不好的 –