我有这个 router.ts
{ path: 'resetPasswordRequest/:id', component: ResetPassIdComponent, canActivate: [AuthGuard]}
在组件 ResetPassIdComponent 中,我使用以下代码获取 id:
ngOnInit(): any {
let myid = this.route.snapshot.paramMap.get("id")
this.id = myid;
}
我现在想,如何创建它在此组件 ResetPassIdComponent 中导航的 AuthGurad。
我尝试使用此代码但不起作用
更新:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let productId = route.params.id;
if (this.auth.isAuthenticated()) {
return true;
}
this.router.navigate(['/resetPasswordRequest/' + productId]);
return false;
}
在控制台中显示:resetPasswordRequest/123456789
但不要在此处导航组件。