【发布时间】:2018-12-25 08:44:20
【问题描述】:
当我使用 canActivate(); 时,我想直接在组件ResetPassIdComponent 中导航;现在,当我单击此组件 ResetPassIdComponent 时,我的应用程序首先在 /outsidelogin/login 中导航,然后在 resetPasswordRequest/:id 中导航
export class AuthGuard implements CanActivate {
constructor(private router: Router, private auth: LoginService) { }
canActivate(): boolean {
if (this.auth.isAuthenticated()) {
return true;
}
this.router.navigate(['/outsidelogin/login']);
return false;
}
}
所以在这个 canActivate() 中我有 2 个条件,第一个如果我登录,第二个如果我没有登录导航 this.router.navigate(['/outsidelogin/login']);
我的路由.ts
const routes: Routes = [
{
path: 'home',
component: HomeComponent,
canActivate: [AuthGuard],
children: [
{
path: 'fp', component: FirstPageComponent
}
]
},
{
path: 'outsidelogin',
component: outsideloginComponent,
children: [
{ path: 'login', component: LoginFirstComponent },
{ path: 'register', component: RegisterComponent },
]
},
{ path: '', redirectTo: '/home/fp', pathMatch: 'full' },
{ path: 'resetPasswordRequest/:id', component: ResetPassIdComponent }
];
拜托,你能告诉我任何想法,如何解决我的问题吗?
【问题讨论】:
-
您能否与我分享 (stackblitz.com) 链接,因为您没有正确理解您的观点。
-
我演示了这个演示 play.nativescript.org/?template=play-ng&id=PmLIFr&v=2 我想在 AuthGuard 中添加一个条件,如果我在
resetPasswordRequest/:id中有一个 id,我想直接在ResetPassIdComponent中导航。在我的演示中,假设 Id 为 123,应直接导航到组件 ResetPassIdComponent -
你能看到我的演示吗 github.com/binaau/auth_guard 安装后,请点击这个链接 stackoverflow.com/questions/53921510 并使用应用程序打开。此时,您可以看到该应用程序首先在登录组件中导航,然后在重置通道中进行第二次导航。我只想在单击链接时直接在重置通道中导航。谢谢!
标签: angular routing nativescript canactivate