Javascript 角防护装置不在儿童路径中工作

Javascript 角防护装置不在儿童路径中工作,javascript,angular,typescript,angular-router-guards,Javascript,Angular,Typescript,Angular Router Guards,我在creditscore childpages设置了一个守卫,但它似乎不起作用。如果用户未通过身份验证,我将尝试重定向回/creditscore页面,但当我访问/crediscore/verification页面时,即使启用了防护,它也不会重定向回/creditscore页面。 我已经尝试了下面的代码 const routes: Routes = [ { path: '**', component: CreditScoreComponent, resolve: {

我在creditscore childpages设置了一个守卫,但它似乎不起作用。如果用户未通过身份验证,我将尝试重定向回
/creditscore
页面,但当我访问
/crediscore/verification
页面时,即使启用了防护,它也不会重定向回
/creditscore
页面。 我已经尝试了下面的代码

const routes: Routes = [
  {
    path: '**',
    component: CreditScoreComponent,
    resolve: { config: WPConfigResolver },
    children: [
      {
        path: 'verification',
        component: CreditScoreSelectorComponent,
        canActivate: [ResultsGuard],
      },
      {
        path: 'results',
        component: CreditScoreResultsComponent,
        canActivate: [ResultsGuard],
      }
    ]
  }
];

export const routing: ModuleWithProviders = RouterModule.forChild(routes);
这是我的结果

canActivate(): boolean  {
    if (this.authService.isAuthenticatedUser()) {
      return true;
    } else {
      this.router.navigate(['/creditscore']);
      return false;
    }
  }

这是正确的方法吗?提前谢谢。

你说的“重定向到页面”是什么意思?哪一页?也许你会提到你试图导航到的路径,以及你最终要走的路径。我已经更新了这个问题。如果用户未通过身份验证,我需要重定向回creditscore登录页。您是否检查了
this.authService.isAuthenticatedUser()返回的值
您可以将console.log(this.authService.isAuthenticatedUser())
放在guard中的if语句之前。此方法可能每次都返回
true
。它正在按预期返回。如果经过身份验证,则返回
true
else
false
。我只是不明白为什么警卫不工作。也许它与路径“**”有关?您能提供stacklitz吗?