I'm trying to get my Angular routes to lazy load. I've got a working version in another app, and as far as I can tell have implemented it in an identical way - however it simply doesn't work. There's no errors, just an empty <router-outlet>.
Here's my app.module.ts. The SharedModule and EntityViewsModule contain shared components:
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
SharedModule,
EntityViewsModule,
FormsModule,
HttpModule,
routing,
...rxjs stuff...
],
providers: [
...bunch of services...
],
bootstrap: [AppComponent]
})
export class AppModule { }
routing is defined:
import { RouterModule, Route } from '@angular/router';
import { ModuleWithProviders, Component } from '@angular/core';
const routes: Route[] = [
{ path: '', pathMatch: 'full', redirectTo: 'home'},
{ loadChildren: 'app/frontScreen/frontScreen.module#FrontScreenModule', path: 'home' },
];
export const routing: ModuleWithProviders = RouterModule.forRoot(
routes,
{
useHash: true
}
);
and the module I'm trying to load:
@NgModule({
imports: [
CommonModule,
EntityViewsModule,
SharedModule
],
declarations: [
FrontScreenComponent
],
bootstrap: [
FrontScreenComponent
]
})
export class FrontScreenModule { }
It works fine with eager loading where I define component: FrontScreenComponent and manually import the FrontScreenModule. But fails silently with the above configuration.
One clue might be that the redirect isn't even working. Typing 'http://localhost:4200/#/' into the address bar does not redirect to 'http://localhost:4200/#/home' like I'd expect.
FrontScreenModuleinto your app module