【发布时间】:2020-02-27 03:33:32
【问题描述】:
我有一个 Angular 7 应用程序,其中我有这样的路线
{ path : 'forgot-password/:resetHash/:email',
component : ForgotPasswordComponent,
canActivate : [ForgotPasswordPageGuard]},
现在我尝试访问这条路由的params,它是route-guard,但我没有得到路由参数。这是我的forgotpassword.route.guard.ts
constructor(private _utilityService: UtilitySerivce, private _dataService: DataService, private _const: Constants, private _router: ActivatedRouteSnapshot) {
}
canActivate = (): boolean => {
console.log('in link expiry guard')
let userEmail = this._router.paramMap.get('email');
let isAllow = false;
console.log('params : ', userEmail)
userEmail = this._utilityService.decryptMsgByCryptoJs(userEmail);
console.log('user email : ', userEmail)
this._dataService.post(this._const.userResetPasswordLinkExpiry, { email: userEmail }).subscribe(resp => {
if (resp.success) {
isAllow = true;
} else {
isAllow = false;
}
})
if (isAllow) {
return true;
} else {
this._utilityService.navigate('/login');
this._dataService.exhangeResetPasswordObsMsg({ event: 'linkExpired' });
return false;
}
}
但它给出了这个错误
我做错了什么?
【问题讨论】:
-
错字警告:这是一个守卫 - 而不是“守卫” ....
标签: angular typescript angular-routing angular-route-guards