Как выполнить маршрутизацию в компоненте при использовании AuthGuard в Nativescript - PullRequest
0 голосов
/ 21 декабря 2018

Я использую nativescript-urlhandler в своей Nativescript Aplication.Когда я помещаю маршрутизатор, мое приложение направляется сначала в LoginFirstComponent, а во вторую в ResetPassIdComponent, который я хочу.

Я хочу направить непосредственно к компоненту, который я хочу.

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;
    }

Мой AuthGuardReset.ts не перемещается к ResetPassIdComponent, он остается в LoginFirstComponent.

В component.ts Iесть этот код:

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);
        });
    }

Можете ли вы поделиться со мной любой идеей, как решить эту проблему, пожалуйста?

1 Ответ

0 голосов
/ 21 декабря 2018

Попробуйте это: - получить значение true вместо false

 canActivate(): boolean {
    if (this.auth.isAuthenticated()) {
        return true;
    }
    this.router.navigate(['/outsidelogin/resetPasswordRequest/:id']);
    return true;
}

Для получения более подробной информации см. Ссылку на этот пример Как использовать угловые 6 Route Auth Guard для всех маршрутов Root и Child Routes?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...