Angular 7 router '**' wildcard with lazy load module and child routes not working?

爷,独闯天下 提交于 2019-12-08 14:47:29

The lazy modules require two routing configuration. The first one which is in the appModule tells the angular when to load the module. The second one which is in the lazy feature module, tells the angular when to display a specific component.

In your case, change the path of the appModule routing to be hello. This tells the angular to download the lazy module when sees the hello url. As of the second configuration, leave it empty. This tells angular to load the component when it sees an empty string following the hello url

AppModule

export const routes = [
  {
    path: '',
    component: 'DashboardComponent'
  },
  {
    path: 'helllo', <-- change this
    loadChildren: './lazy/lazy.module#LazyModule'
  }
];

LazyModule

const routes = [
  {
    path: '', 
    component: LazyComponent // I do not know what this is. The components are not lazy. Modules are
  }
  {
    path: '',  <-- change this
    component: HelloComponent
  }
];

I saw in your code that you have a LazyComponent. I do not know what you are trying to achieve with this but the components are not lazy. Modules are.

I believe you have to redirect to an actual route. There are a few topics related to this, here is one. Also per Angular's examples, you might have to export your RouterModule from LazyModule.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!