尝试将模块延迟加载到angular2 rc中。应用程式。该模块本身包含路由。该应用程序尝试在单击模块注册的路径时延迟加载模块,但立即抛出
Error: Uncaught (in promise): Error: Cannot find 'default' in './app/test/test.module'
应用中的路线定义如下:
export const routes: Routes = [
{ path: '', component: StartComponent },
{ path: 'route1', component: Route1Component },
{ path: 'test', loadChildren: './app/test/test.module'},
{ path: '**', component: StartComponent } //page not found
];
TestModule包含以下路由:
export const TestRoutes: Routes = [
{ path: '', redirectTo: 'overview' },
{ path: 'overview', component: TestOverviewComponent },
{ path: 'moredata', component: MoreDataComponent }
];
我删除了redirectTo,并指出了到真实组件的默认路由,没有运气。还尝试过与诸如
export const AdminRoutes: Routes = [
{
path: 'test', component: TestComponent,
children: [
{ path: '', redirectTo: 'overview' },
{ path: 'overview', component: TestOverviewComponent },
{ path: 'moredata', component: MoreDataComponent }
]
}
];
结果相同。
任何提示可能有什么问题吗?加载模块会按预期完成。
问候
您必须将模块的导出类名添加到loadChildren字符串中,例如
{ path: 'test', loadChildren: './app/test/test.module'},
改成
{ path: 'test', loadChildren: './app/test/test.module#TestModule'},
如官方文档https://angular.io/docs/ts/latest/guide/router.html中所述
如果我们仔细查看loadChildren字符串,可以看到它直接映射到我们先前建立Crisis Center功能区域的crisis-center.module文件。在文件路径之后,我们使用#表示文件路径的结尾,并告诉路由器CrisisCenter NgModule的名称。如果我们查看crisis-center.module文件,我们可以看到它与导出的NgModule类的名称匹配。
某些博客文章中缺少此部分,例如
https://angularjs.blogspot.de/2016/08/angular-2-rc5-ngmodules-lazy-loading.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句