Angular 2 Guards: canLoad() Is Firing Twice any Reason?

932 views Asked by At

canLoad Is Firing Twice On Rejection or Even In Acceptance

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

canLoad Implementation

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

Servie Method Invoked

Assuming Observale Boolean Response Will be returned

IsModuleCanbeLoaded(): Observable<boolean> {         
    return false as Observable<boolean>;
}
0

There are 0 answers