0

Use Case:

I want to use angular guards canActivate to redirect a Info site.

the code with canActivate is as follow:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable< boolean | UrlTree>{
    this.fserviceFacade.loadData();

     return new Observable(obs => 
      this.fserviceFacade.currentData$
       
      
      .subscribe( (result) => {
        if(result){

          //this.router.parseUrl('/xxxx/xxxx')
          //this.router.createUrlTree(['/xxxx/xxxx']);
          //obs.next(this.router.parseUrl('/xxxx/xxxx') )
          obs.next(true);
        }
      
      }));

  }

and then I registrated this servcie DataCheckServcie in my route:

const routes: Routes = [
  {
    path: 'Adress',
    component: AdressComponent,
    canActivate: [AuthGuard, PermissionGuard, DataCheckServcie],
    
  },

What is the problem,

it can not redirect to the site /xxx/xxx what I expected.

the in console the site will be always reloaded, reloaded...

Maybe you can give me some solutions?

user1938143
  • 1,022
  • 2
  • 22
  • 46

0 Answers0