I'm loading a books module with the following routing configuration (src/app/index.ts) --请注意,这是一个stackblitz链接-它现在通过实现答案中的修复来工作-要断开它,请从图书模块路由中删除authguard:
{
path: 'books',
loadChildren: './books/books.module#BooksModule',
canActivate: [AuthGuard],
},books模块(src/app/books/index.ts)中的路由如下所示:
export const routes: Routes = [
{ path: '', component: CollectionPageComponent },
];由于某些原因,加载此路由会关闭AuthGuard / CanActivate防护不会触发。它里面有一个日志记录语句,跟踪它何时触发。
如果路由被注释掉,如下所示:
export const routes: Routes = [
//{ path: '', component: CollectionPageComponent },
];然后守卫就会触发。有什么想法?
发布于 2019-01-03 00:30:21
问题是authguard需要存在于您的BooksModule路由定义中。
#in books/index.ts
export const routes: Routes = [
{ path: '', component: CollectionPageComponent, canActivate: [AuthGuard] },
];然后,您可以从canActivate /index.ts中删除该应用程序
发布于 2019-01-03 00:33:03
您只能将canActivate防护与组件一起使用。如果您希望在延迟加载的模块上使用canLoad guard。
https://stackoverflow.com/questions/54009560
复制相似问题