我正在尝试使用具有角度 6 业力的惰性模块来测试路由器导航。但我收到控制台错误
Cannot find module app/features/landing/landing.module#landingPageModule
.
然后我用
loader = TestBed.get(NgModuleFactoryLoader);
loader.stubbedModules = {
'landingPageModule': LandingPageModule
};
router.resetConfig([
{path: 'main', loadChildren: 'landingPageModule'},
{path: 'main/auth/login', loadChildren: 'AuthModule'},
{path: 'main/auth/sign-up', loadChildren: 'AuthModule'}
]);
当我导航时一切都很好
{path: 'main', loadChildren: 'landingPageModule'},
但是当我导航时
{path: 'main/auth/login', loadChildren: 'AuthModule'},
我还在
Cannot find module
app/features/auth/auth.module#AuthModule
控制台上的错误。
LandingPageroutes 看起来像这样
export const landingPageRoutes: Routes = [
{path: '', component: HomeComponent, canActivate: [AuthGuard],data: {roles: ['user']}},
{
path: 'auth', component: LandingPageComponent, children: [
{path: '', pathMatch: 'full', redirectTo: 'login'},
{path: '', loadChildren: 'app/features/auth/auth.module#AuthModule'},
]
},
AuthModule 在 LandingPageModule 上声明,所以我需要在“SpyNgModuleFactoryLoader”上存根 2 个模块,但它不起作用
loader = TestBed.get(NgModuleFactoryLoader);
loader.stubbedModules = {
'AuthModule' : AuthModule,
'landingPageModule': LandingPageModule
};