RC.5 throws \"Cannot find 'default' when lazy loading module with routes

雨燕双飞 提交于 2019-12-03 11:14:04

You have to add the exported class name of your module to the loadChildren string, like

{ path: 'test', loadChildren: './app/test/test.module'},

change to

{ path: 'test', loadChildren: './app/test/test.module#TestModule'},

as stated in official documentation https://angular.io/docs/ts/latest/guide/router.html

If we look closer at the loadChildren string, we can see that it maps directly to our crisis-center.module file where we previously built out our Crisis Center feature area. After the path to the file we use a # to denote where our file path ends and to tell the Router the name of our CrisisCenter NgModule. If we look in our crisis-center.module file, we can see it matches name of our exported NgModule class.

this part is missing in some blog posts, e.g.

https://angularjs.blogspot.de/2016/08/angular-2-rc5-ngmodules-lazy-loading.html

Modidfy your module file ./app/test/test.module. as

export default class TestModule{}

You must have skipped the "default" keyword.

OR what else you can do is,

export const AdminRoutes: Routes = [

  { path: '', redirectTo: 'test', pathMatch: 'full'},  //<----added this


  {
    path: 'test', component: TestComponent,
    children: [
          { path: '', redirectTo: 'overview' },
          { path: 'overview', component: TestOverviewComponent },
          { path: 'moredata', component: MoreDataComponent }
    ]
  }
];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!