Angular2:相当于没有延迟加载的路由器"loadChildren" [英] Angular2: What's the equivalent of the router 'loadChildren' without lazy loading
问题描述
我正在尝试将包含路由配置(从RouterModule.forChild()
导入)的子ngModule(功能模块)插入"到父ngModule中.
I'm trying 'plug' a sub ngModule (a feature module ) containing routing configurations (imported from RouterModule.forChild()
) into a parent ngModule.
使用延迟加载时,使用父模块路由配置中的loadChildren
键指定在何处插入"子模块.
When using lazy loading, specifying where to 'plug' the child module is done using the loadChildren
key in the parent module route configuration.
ex:
export const parentModuleRouteConfig = [{
path: 'myfeaturemodule',
loadChildren: '/app/child.module'
}];
实际上,我不想使用延迟加载.
如何告诉路由器插入"(或使用)在给定路径的子模块中指定的路由配置?
推荐答案
带有AOT
导出您的子路线,而不是将其添加到您的子模块中.
With AOT
Export your child routes instead of adding them to your child module.
export const ChildRoutes: Routes = [
{ path: '', component: ChildComponent }
];
将子模块导入父模块并直接包含路由.
Import the child module into the parent module and include routes directly.
const parentModuleRouteConfig: [{
path: 'myfeaturemodule',
// loadChildren: () => ChildModule
children: ChildRoutes
}];
@NgModule({
imports: [
ChildModule
]
})
export class ParentModule { }
没有AOT
您仍然可以使用loadChildren进行同步加载.在此github问题中有一些示例 .
import { ChildModule } from '/app/child.module';
export const parentModuleRouteConfig = [{
path: 'myfeaturemodule',
loadChildren: () => ChildModule
}];
这篇关于Angular2:相当于没有延迟加载的路由器"loadChildren"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!