export const ROUTES: Routes = [
{
path: 'Inbox',
canLoad: [CanActivateViaAuthGuardService],
loadChildren: 'LazyLoaded module',
}
]
canLoad(route: Route): Observable<boolean> {
console.log("CanLoad Is Called?");
return this._apsm.IsModuleCanbeLoaded()
.map(
res => {
console.log(res);
if (res === false) {
// User:Don't Has Access
this.router.navigateByUrl('/error');
return false;
}
// User Has Access:
return true;
})
.catch((error: any) => {
console.log(error);
this.router.navigateByUrl('/error');
return Observable.of(false);
});
}
假设将返回Observale布尔响应
IsModuleCanbeLoaded(): Observable<boolean> {
return false as Observable<boolean>;
}