嗨,我目前正在制作Angular应用程序,我有2个模块:GuessModule和AdminModule;该模块中的一个应始终加载GuessModule,另一个应具有canLoad防护。
// app-routing.module.ts
const routes: Routes = [
{
path: '',
loadChildren: () => import('./modules/guest/guest.module').then(m => m.GuestModule),
},
{
path: 'admin',
loadChildren: () => import('./modules/admin/admin.module').then(m => m.AdminModule),
canLoad: [
AuthGuard
],
},
{
path: '**',
redirectTo: '/'
}
];
// app.component.html
<router-outlet></router-outlet>
我有一个带有AuthGuard的CoreModule:
/// CoreModule forRoot called in app.module imports CoreModule.forRoot()
static forRoot(): ModuleWithProviders {
return {
ngModule: CoreModule,
providers: [
AuthGuard
],
} as ModuleWithProviders;
}
在我的Auth Guard中,我有这个:
canLoad(
route: Route,
segments: UrlSegment[]): Observable<boolean> | Promise<boolean> | boolean {
return false; // to test
}
但是当我沿路线“ /”行驶时,我装载了2个模块,但只应该装载GuessModule,我也不知道为什么都装载了这两个模块; canLoad不会触发,但是AdminModule已加载。
我想念什么吗?
谢谢。