Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lazyloading Angular2中其他模块的孩子_Angular_Angular2 Routing - Fatal编程技术网

Lazyloading Angular2中其他模块的孩子

Lazyloading Angular2中其他模块的孩子,angular,angular2-routing,Angular,Angular2 Routing,我遇到了一个问题,在应用程序根级别显示子路由 我的应用程序由根应用程序模块构成,根应用程序模块导入SecureModule和PublicModule。然后,SecureModule导入ProviderModule和PracticeModule。每个模块都使用.forChild定义自己的路由(定义forRoot的AppModule除外)。由于某些原因,每个模块中的所有默认路径(以“”作为路径列出的路径)都存在于根应用程序模块级别 下面是一个示意根树的占卜图: SecureComponent是一个

我遇到了一个问题,在应用程序根级别显示子路由

我的应用程序由根应用程序模块构成,根应用程序模块导入SecureModule和PublicModule。然后,SecureModule导入ProviderModule和PracticeModule。每个模块都使用.forChild定义自己的路由(定义forRoot的AppModule除外)。由于某些原因,每个模块中的所有默认路径(以“”作为路径列出的路径)都存在于根应用程序模块级别

下面是一个示意根树的占卜图:

SecureComponent是一个功能组件(无选择器),用于定义安全区域的布局,并具有自己的路由器出口。正如您从根目录树中看到的,实践和提供者模块路径完美地布局在它下面。然而,实践和提供者模块也直接来自AppComponent

我通过loadChildren懒洋洋地加载子路径,并在默认路径上使用pathMatch full,因此我不确定它们为什么要附加到根组件

我的安全模块路由定义如下:

export const secureRoutes = [
{
    path: 'secure', component: SecureComponent, children: [
        { path: '', redirectTo: 'firstuse', pathMatch: 'full' },
        { path: 'firstuse', component: FirstUseComponent },
        { path: 'practice', loadChildren: './+practice#PracticeModule' },
        { path: 'provider', loadChildren: './+provider#ProviderModule' }
    ]
},
])

我的实践路线定义如下:

export const practiceModuleRoutes = [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: PracticeDashboardComponent },
{ path: ':id', component: PracticeViewerComponent }
];
export const appModuleRoutes: Routes = [
{ path: '', redirectTo: 'public', pathMatch: 'full' },
{ path: 'public', component: PublicComponent },
{ path: 'id_token', redirectTo: 'secure' },
{ path: 'logoff', component: LogoffComponent },
{ path: 'Unauthorized', component: UnauthorizedComponent },
{ path: '**',    component: NoContentComponent },
];
我的应用程序路由定义为:

export const practiceModuleRoutes = [
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: PracticeDashboardComponent },
{ path: ':id', component: PracticeViewerComponent }
];
export const appModuleRoutes: Routes = [
{ path: '', redirectTo: 'public', pathMatch: 'full' },
{ path: 'public', component: PublicComponent },
{ path: 'id_token', redirectTo: 'secure' },
{ path: 'logoff', component: LogoffComponent },
{ path: 'Unauthorized', component: UnauthorizedComponent },
{ path: '**',    component: NoContentComponent },
];

有人知道为什么这些实践和提供者默认路由出现在根应用程序组件上吗?

我刚刚意识到我的AppModule正在导入安全和公共模块。当它这样做时,它似乎已经包含了这些模块在根级别的路由。当loadChildren发生时,它还为这些路由加载了正确的路径,这就是它们在这两个位置都存在的原因

为了解决我的问题,我从AppModule中删除了SecureModule和PublicModule的导入。这为路径仅作为子路径加载扫清了道路