2017-03-08 149 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'(這是我想要的),但我也可以手動去''''哪個是不好的 –