0

I have generic guard for many applications:

export class Guard implements CanActivate {
    constructor(private authService: AuthService, private router: Router, private route: ActivatedRoute) {}
    async canActivate(route: ActivatedRouteSnapshot) {
        const user = await this.authService.getUserAuthenticated();
        const hasPerm = user && user.hasPermission(route.data.app);
        if (!hasPerm) {
            this.router.navigate(['/login/' + this.route.snapshot.params.site, {}]);
        }
        return true;
    }
}

But this.route.snapshot.params.site is empty for route : "/signin/macro/561".

the route declaration :

{ path: 'signin/:site/:token', loadChildren: 'src/app/auth/auth.module#AuthModule' },
Abhishek
  • 1,742
  • 2
  • 14
  • 25
yantrab
  • 2,482
  • 4
  • 31
  • 52

1 Answers1

0

Try using ActivatedRoute and access the params as this.activatedRoute.snapshot.params.site. Plus you're using ActivatedRouteSnapshot and trying to access the snapshot property of it, which will obviously be undefined because it doesn't have any such property. You can try directly accessing the params in that case.