Angular 有棱角的防护装置不能正常工作

Angular 有棱角的防护装置不能正常工作,angular,typescript,angular8,angular-guards,Angular,Typescript,Angular8,Angular Guards,我试图将不涉及身份验证的新用户重定向到首次使用该应用程序的国家/地区选择。 我使用有棱角的护卫,而且我很懒。 我正在检查以下链接:。 然而,问题是,由于我是惰性加载的,所以我尝试如下实现它 app.module.ts const routes: Routes = [ { path: '', loadChildren: './pages/main/main.module#MainPageModule', canActivate: [TutorialGuard]}, ] 主页,它是主页和收藏夹页

我试图将不涉及身份验证的新用户重定向到首次使用该应用程序的国家/地区选择。 我使用有棱角的护卫,而且我很懒。 我正在检查以下链接:。 然而,问题是,由于我是惰性加载的,所以我尝试如下实现它

app.module.ts

const routes: Routes = [
{ path: '', loadChildren: './pages/main/main.module#MainPageModule', 
canActivate: [TutorialGuard]},
]
主页,它是主页和收藏夹页面的父级

    const routes: Routes = [
  {
    path: 'main',
    component: MainPage,
    children: [
       { path: 'home', loadChildren: '../home/home.module#HomePageModule' 
},
      { path: 'favorites', loadChildren: 
'../favorites/favorites.module#FavoritesPageModule' },
      { path: 'country-selection', loadChildren: '../country- 
   selection/country-selection.module#CountrySelectionPageModule' },

    ]
  },
  {
    path: '',
    redirectTo: '/main/home',
  }
];
tutorial.guard.ts

编译后,屏幕将变为白色,我在tutorial.guard.ts中提到的console.log部分将永远运行


你能告诉我我做错了什么吗?

我想问题是你把它设置在了默认路线上。
这意味着,由于不允许您进入此路径,应用程序试图引导您进入默认路径,即相同的路径,因此您陷入了循环。

您在这两个位置都提到了根模块作为主页模块。所以它是一个无限循环,变成了一个空白循环。注意:当您使用延迟加载模块时,请使用canLoad而不是canActivate

App.module.ts

const routes: Routes = [
{ path: '', loadChildren: './pages/main/main.module#MainPageModule', 
canActivate: [TutorialGuard]},
]
主页:

  {
    path: '',
    redirectTo: '/main/home',
  }

您不需要在app.module.ts中定义常量路由。在导入中添加以下RouterModule.forRootTutorialGuard,{useHash:true}
  {
    path: '',
    redirectTo: '/main/home',
  }