0

我在 Nativescript 中有一个项目。我的项目中的问题在于 CanActivate。使用 AuthGuard 时,我的 canActivate 不会在另一个页面中导航。

我有这个routing.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: 'test',
    component: outsideloginComponent,
    canActivate: [AuthResetGuard],
    children: [
       { path: 'resetPasswordRequest/:id', component: ResetPassIdComponent }
    ]
  },

    { path: '', redirectTo: '/home/fp', pathMatch: 'full' }
];

在 AuthResetGuard.ts 我有这个代码:

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    let productId = route.params.id;
    if (this.auth.isAuthenticated()) {
        return true;
    }
    this.router.navigate(['/test/resetPasswordRequest/' + productId]);
    console.log('/test/resetPasswordRequest/' + productId)
    return true;

}

在这个 ResetPassIdComponent .ts 我有

  ngOnInit(): any {
    let myid = this.route.snapshot.paramMap.get("id")
    this.id = myid;
  }

错误:当我点击http://xxxxxx.com/v1/resetPasswordRequest/11111时,我的应用程序没有打开,只显示 splash_screen 并且在控制台中只显示所有时间

JS: /test/resetPasswordRequest/11111
JS: /test/resetPasswordRequest/11111
JS: /test/resetPasswordRequest/11111
JS: /test/resetPasswordRequest/11111
JS: /test/resetPasswordRequest/11111

请有任何想法,如何解决我的问题?

4

0 回答 0