0

I want to navigate directly in here component ResetPassIdComponent whene I use canActivate(); Now, when I click for this component ResetPassIdComponent , my aplication navigate in first in /outsidelogin/login and in second in 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;
    }
}

So in this canActivate() I have 2 conditions, first if I'm login and second if I'm not login navigate in this.router.navigate(['/outsidelogin/login']);

My 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: '', redirectTo: '/home/fp', pathMatch: 'full' },
    { path: 'resetPasswordRequest/:id', component: ResetPassIdComponent }
];

Please, Can you share with me any idea, how to solve my problem?

4

1 回答 1

0

首先需要在resetPasswordRequest/:id 中获取参数,如果登录则获取参数如下并将字符串转换为数字。您必须将身份验证令牌存储在浏览器缓存中。

    // import in resetPasswordeRquest Component.
    import { Route, AcivatedRoute } from '@angular/router'; 

    // inside component class;
    id: number;
    constructor(private router: Router, private route: ActivatedRoute){
       this.route.paramMap.subscribe(params => {
          this.id = +params.get('id');   
       }           
    }
于 2018-12-26T06:29:05.457 回答