Lazy Load to route other than empty route in Angular 2 Lazy Load to route other than empty route in Angular 2 angular angular

Lazy Load to route other than empty route in Angular 2


You have to add Routes to your childmodule

  const routes: Routes = [  { path: '', component: ResetComponent}  ];  const ROUTES: ModuleWithProviders =   RouterModule.forChild(routes);

and import ROUTES in child module(ResetModule)

@NgModule({ imports: [    CommonModule,    ROUTES,    ], declarations: [ResetComponent], exports: [ResetComponent]})


This problem might happen because of the imports you have added in imports:[ ] of AppModule (or any other module file).

Make sure to remove all the lazily loaded modules from the imports array.

for eg: I have three modules named:HomeModule, ProfileModule and SettingsModule.if HomeModule is eagarly loaded and ProfileModule and SettingsModule are lazily loaded, then imports:[] of AppModule(app.module.ts) should look like this:

imports:[HomeModule] and it shouldn't include ProfileModule or SettingsModule because they will be loaded automatically during runtime.