Angular2:没有延迟加载的路由器“loadChildren"的等价物是什么 [英] Angular2: What's the equivalent of the router 'loadChildren' without lazy loading

查看:30
本文介绍了Angular2:没有延迟加载的路由器“loadChildren"的等价物是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将包含路由配置(从 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.

例如:

export const parentModuleRouteConfig = [{
    path: 'myfeaturemodule',
    loadChildren: '/app/child.module'
}];

实际上,我不想使用延迟加载.

如何告诉路由器插入"(或使用)子模块中指定路径的路由配置?

推荐答案

With 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆