0

I have a project in Nativescript. My problem in my project is in CanActivate. My canActivate don't navigate in another page when use AuthGuard.

I have this 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' }
];

in AuthResetGuard.ts I have this code:

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;

}

In this ResetPassIdComponent .ts I have

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

ERROR: When I click in http://xxxxxx.com/v1/resetPasswordRequest/11111, My application don't open , only show splash_screen and in console show all of time only

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

Any idea please, how to solution my problem ?

web site
  • 99
  • 8
  • You navigate To the url that launches AuthResetGuard which controls the url test/reset... and calls the same url recursively. – mth khaled Dec 24 '18 at 14:14
  • Can you write some code please? – web site Dec 24 '18 at 14:19
  • What happens if you remove `this.router.navigate(['/test/resetPasswordRequest/' + productId]);` from `AuthResetGuard`? That is redundant i guess. – Amit Chigadani Dec 24 '18 at 14:53
  • If I remove `this.router.navigate(['/test/resetPasswordRequest/' + productId]);` from AuthResetGuard don't navigate in this ResetPassIdComponent component – web site Dec 24 '18 at 15:01
  • what happen when you manually hit /test/resetPasswordRequest/11111?does it navigate? – umesh99 Dec 24 '18 at 15:20

0 Answers0