我有一個應用程序,它需要分離已驗證和來賓用戶組件。但我需要,這兩個組件都將通過'/'路線加載。我寫了角度2具有相同路由的不同組件
{
path: 'desktop',
loadChildren: 'app/member/member.module#MemberModule',
canActivate: [LoggedInGuard],
},
{
path: '',
loadChildren: 'app/guest/guest.module#GuestModule',
canActivate: [GuestGuard],
},
它工作。但如何使這兩個組件加載相同的網址? 我曾嘗試爲成員的模塊路由寫入path: ''
,但未執行第二個路由器規則。 這裏有守衛代碼:
LoggedInGuard:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if(this.sessionService.isLoggedIn()) {
return true;
} else {
return false;
}
}
GuestGuard:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if(!this.sessionService.isLoggedIn()) {
return true;
} else {
return false;
}
}
這裏是一個plunker:http://embed.plnkr.co/VaiibEVGE79QU8toWSg6/
我應該怎樣做正確?謝謝
什麼是錯誤? – echonax
對不起。沒有錯誤。但只執行第一個路由器規則 –
如果沒有錯誤和第一個路由器規則滿足,那麼你的LoggedInGuard返回true? – echonax