试图在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 }
]
}
];
结果相同 .
什么提示可能有什么问题?加载模块急切地按预期工作 .
问候
3 回答
您必须将模块的导出类名添加到loadChildren字符串中,例如
改成
如官方文件中所述https://angular.io/docs/ts/latest/guide/router.html
某些博文中缺少此部分,例如
https://angularjs.blogspot.de/2016/08/angular-2-rc5-ngmodules-lazy-loading.html
将模块文件
./app/test/test.module.
修改为您必须跳过“default”关键字 .
或者你还能做什么,