0

我正在尝试使用具有角度 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
    };
4

1 回答 1

0

问题出在

 router.resetConfig([
        {path: 'main', loadChildren: 'landingPageModule'},
        {path: 'main/auth/login', loadChildren: 'AuthModule'},
        {path: 'main/auth/sign-up', loadChildren: 'AuthModule'}
    ]);

无需声明 2 个不同的模块,router.resetConfig 只需将更改替换AuthModulelandingPageModule.

     router.resetConfig([
        {path: 'main', loadChildren: 'AuthModule'},
        {path: 'main/auth/login', loadChildren: 'AuthModule'},
        {path: 'main/auth/sign-up', loadChildren: 'AuthModule'}
    ]);
于 2018-05-25T14:55:43.410 回答