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

811 Views Asked by At
{
    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?


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

1

There are 1 best solutions below

0
On BEST ANSWER
canActivate(activatedRouteSnapshot: ActivatedRouteSnapshot) { ... }

sovled the problem: method parameter should be prefered over constructor injection.