0

canLoad 在拒绝或接受时触发两次

export const ROUTES: Routes = [
    {
        path: 'Inbox',
        canLoad: [CanActivateViaAuthGuardService],
        loadChildren: 'LazyLoaded module',
    }
]

canLoad 实现

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>;
}
4

0 回答 0