My goal is : When hit the link 'auth/login/:tokenKey'
a method will fire and then redirect A or B ponent. For this link 'auth/login/:tokenKey'
, no need a ponent. It should be only a method in ts file.
How to do that ?
GetTokenKeyGuard.ts
canActivate(route: ActivatedRouteSnapshot) {
localStorage.setItem('token_key', route.params.tokenKey);
return true;
}
I dont need to use a ponent for 'auth/login/:tokenKey'
path. In that path, a process will run and then will be redirected to index page.
But when i use 'redirectTo' directive, Guard doesnt work.
When i use with ponent, Guard works.
How to use guard without ponent ?
app-routing.module.ts
const routes: Routes = [
{ path: '', ponent: IndexComponent },
{ path: 'auth/login', ponent: LoginComponent },
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
redirectTo: '' }, //........................ Guard doesnt work.
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
ponent: LoginComponent }, //............. Guard works.
];
My goal is : When hit the link 'auth/login/:tokenKey'
a method will fire and then redirect A or B ponent. For this link 'auth/login/:tokenKey'
, no need a ponent. It should be only a method in ts file.
How to do that ?
GetTokenKeyGuard.ts
canActivate(route: ActivatedRouteSnapshot) {
localStorage.setItem('token_key', route.params.tokenKey);
return true;
}
I dont need to use a ponent for 'auth/login/:tokenKey'
path. In that path, a process will run and then will be redirected to index page.
But when i use 'redirectTo' directive, Guard doesnt work.
When i use with ponent, Guard works.
How to use guard without ponent ?
app-routing.module.ts
const routes: Routes = [
{ path: '', ponent: IndexComponent },
{ path: 'auth/login', ponent: LoginComponent },
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
redirectTo: '' }, //........................ Guard doesnt work.
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
ponent: LoginComponent }, //............. Guard works.
];
Share
Improve this question
edited Feb 9, 2019 at 0:43
canmustu
asked Feb 9, 2019 at 0:13
canmustucanmustu
2,6694 gold badges25 silver badges40 bronze badges
2
- Where do you want to redirect to if the login fails? – Cory Kleiser Commented Feb 9, 2019 at 0:26
- Actually, i want to run a method when hit 'auth/login/:tokenKey' and then i will redirect to A ponent or B ponent in that method.... Not need a ponent for this link 'auth/login/:tokenKey'.... Post updated. – canmustu Commented Feb 9, 2019 at 0:41
1 Answer
Reset to default 8You can use below path
const routes: Routes = [
{ path: '', ponent: IndexComponent },
{ path: 'auth/login', ponent: LoginComponent },
{ path: 'auth/login/:tokenKey',
canActivate: [GetTokenKeyGuard],
children: [] }
];
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745499282a4630338.html
评论列表(0条)