我正在尝试用带有angular 6 karma的惰性模块来测试路由器导航。但是我收到了控制台错误
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
};发布于 2018-05-25 22:55:43
问题出在
router.resetConfig([
{path: 'main', loadChildren: 'landingPageModule'},
{path: 'main/auth/login', loadChildren: 'AuthModule'},
{path: 'main/auth/sign-up', loadChildren: 'AuthModule'}
]);不需要在router.resetConfig上声明两个不同的模块,只需用landingPageModule替换AuthModule即可。
router.resetConfig([
{path: 'main', loadChildren: 'AuthModule'},
{path: 'main/auth/login', loadChildren: 'AuthModule'},
{path: 'main/auth/sign-up', loadChildren: 'AuthModule'}
]);https://stackoverflow.com/questions/50531710
复制相似问题