我有这个路由器。
{ 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
但不能在此处组件中导航。