简体   繁体   中英

Can I read route parameter's value from the `canActivate: AuthGuard`?

{
    path: ':l/bla/bla/bla', component: ..., canActivate: [AuthGuard]
}

Then AuthGuard 's constructor:

constructor(
    private readonly router: Router,
    private readonly activedRoute: ActivatedRoute) { }

... however both .params and .snapshot.params are empty and no :l parameter's value (shor for "language") can be read from there.

So question: how can I redirect to another page in case of unauthorized access, having my dynamic :l in place?


PS data does not work (does it?), since it is OKay for a compile-time known data rather than dynamic.

canActivate(activatedRouteSnapshot: ActivatedRouteSnapshot) { ... }

解决了这个问题:方法参数应该比构造函数注入更可取。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM