Angular 在Nativescript中使用AuthGuard时如何在组件中路由
我正在nativescript应用程序中使用nativescript urlhandler。当我放置路由器时,我的应用程序路由首先在LoginFirstComponent中,然后在我想要的ResetPassIdComponent中Angular 在Nativescript中使用AuthGuard时如何在组件中路由,angular,typescript,routing,nativescript,canactivate,Angular,Typescript,Routing,Nativescript,Canactivate,我正在nativescript应用程序中使用nativescript urlhandler。当我放置路由器时,我的应用程序路由首先在LoginFirstComponent中,然后在我想要的ResetPassIdComponent中 const routes: Routes = [ { path: 'home', component: HomeComponent, canActivate: [AuthGuard], children: [ {
const routes: Routes = [
{
path: 'home',
component: HomeComponent,
canActivate: [AuthGuard],
children: [
{
path: 'fp', component: FirstPageComponent
},
{
path: 'profile', component: ProfileComponent
}
]
},
{
path: 'outsidelogin',
component: outsideloginComponent,
canActivate: [AuthGuardReset],
children: [
{ path: 'login', component: LoginFirstComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'resetPasswordRequest/:id', component: ResetPassIdComponent }
]
},
{ path: '', redirectTo: '/home/fp', pathMatch: 'full' }
];
我想直接路由到我想要的组件
const routes: Routes = [
{
path: 'home',
component: HomeComponent,
canActivate: [AuthGuard],
children: [
{
path: 'fp', component: FirstPageComponent
},
{
path: 'profile', component: ProfileComponent
}
]
},
{
path: 'outsidelogin',
component: outsideloginComponent,
canActivate: [AuthGuardReset],
children: [
{ path: 'login', component: LoginFirstComponent },
{ path: 'register', component: RegisterComponent },
{ path: 'resetPasswordRequest/:id', component: ResetPassIdComponent }
]
},
{ path: '', redirectTo: '/home/fp', pathMatch: 'full' }
];
AuthGuard.ts
canActivate(): boolean {
if (this.auth.isAuthenticated()) {
return true;
}
this.router.navigate(['/outsidelogin/login']);
return false;
}
AuthGuardReset.ts
canActivate(): boolean {
if (this.auth.isAuthenticated()) {
return true;
}
this.router.navigate(['/outsidelogin/resetPasswordRequest/:id']);
return false;
}
My AuthGuardReset.ts不会导航到ResetPassIdComponent,它会保留在LoginFirstComponent中
在component.ts中,我有以下代码:
ngOnInit() {
if (this.auth.isAuthenticated()) {
return true;
}
handleOpenURL((appURL: AppURL) => {
console.log('Got the following appURL', appURL);
this.myappurl = appURL
let url_1 = this.myappurl.toString();
let url_id = url_1.split("/").reverse()[0];
this.resetpasss = url_id
this.router.navigateByUrl('/outsidelogin/resetPasswordRequest/' + this.resetpasss);
});
}
你能告诉我如何解决这个问题吗?试试这个:-
复述真伪
canActivate(): boolean {
if (this.auth.isAuthenticated()) {
return true;
}
this.router.navigate(['/outsidelogin/resetPasswordRequest/:id']);
return true;
}
有关更多详细信息,请参阅此示例链接
我单击了一个链接,但应用程序没有打开,没有导航。请参考此示例链接了解更多详细信息。是的,我查看了此示例,但我认为我的问题不同。谢谢你能不能在Heart中举个例子,这样我就可以帮你解决这个问题我想我的问题在HandleOnUrl中,因为它执行了两次,第一次是针对appURL,第二次是针对
this.router.navigateByUrl('/outsidelogin/resetPasswordRequest/'+this.ResetPass)代码>