Is there a way to retrieve the tokenKey value from the URL path in the file GetTokenKeyGuard.ts
?
I attempted to do so using the following code, but it did not work as expected:
canActivate(route: ActivatedRouteSnapshot) {
localStorage.setItem('token_key', route.queryParams.tokenKey);
return true;
}
This approach failed because tokenKey is not passed as a query parameter (i.e., not like localhost/path?tokenKey=blabla
).
const routes: Routes = [
{ path: '', component: IndexComponent },
{ path: 'auth/login', component: LoginComponent },
{ path: 'auth/login/:tokenKey', canActivate: [GetTokenKeyGuard], component: LoginComponent },
];
How can we access the tokenKey variable from the URL path in the file GetTokenKey.ts
?