0

我有许多应用程序的通用防护:

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

但是this.route.snapshot.params.site路线为空:"/signin/macro/561"

路线声明:

{ path: 'signin/:site/:token', loadChildren: 'src/app/auth/auth.module#AuthModule' },
4

1 回答 1

0

尝试使用 ActivatedRoute 并以this.activatedRoute.snapshot.params.site. 另外,您正在使用 ActivatedRouteSnapshot 并尝试访问它的快照属性,这显然是未定义的,因为它没有任何此类属性。在这种情况下,您可以尝试直接访问参数。

于 2019-08-26T10:43:31.070 回答