My objective is to trigger a method and redirect to component A or B when the link 'auth/login/:tokenKey'
is accessed. However, for this specific link, no component is needed, just a method in the typescript file.
How can I achieve this?
GetTokenKeyGuard.ts
canActivate(route: ActivatedRouteSnapshot) {
localStorage.setItem('token_key', route.params.tokenKey);
return true;
}
I want the path 'auth/login/:tokenKey'
to run a process and then direct to the index page without using a component.
Unfortunately, the Guard does not work when I use the 'redirectTo' directive.
The Guard functions properly when used with a component.
Is it possible to use the guard without a component?
app-routing.module.ts
const routes: Routes = [
{ path: '', component: IndexComponent },
{ path: 'auth/login', component: LoginComponent },
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
redirectTo: '' }, //........................ Guard doesnt work.
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
component: LoginComponent }, //............. Guard works.
];