I have .NET Core + Angular 2 / Typescript / SystemJS application. And use lazy loading to load modules
Here is app-routing.module.ts:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{ path: '', loadChildren: 'app/dashboard/dashboard.module#DashboardModule' },
{ path: 'signup', loadChildren: 'app/signup/signup.module#SignUpModule' },
{ path: 'signin', loadChildren: 'app/signin/signin.module#SignInModule' },
{ path: 'welcome', loadChildren: 'app/welcome/welcome.module#WelcomeModule' },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
And welcome-routing.module.ts:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AuthGuard } from './../providers/auth-guard.service';
import { WelcomeComponent } from './welcome.component';
const welcomeRoutes: Routes = [
{ path: '', component: WelcomeComponent, canActivate: [AuthGuard] }
];
@NgModule({
imports: [RouterModule.forChild(welcomeRoutes)],
exports: [RouterModule]
})
export class WelcomeRoutingModule { }
So, when I logged in and go to dashboard page http://example.com/. Then no activity on web app for about 1-2 minutes, and then click on welcome page I sometimes have error (sometimes page loads correctly):
zone.min.js:1 GET http://example.com/app/welcome/welcome.module.js 500 (Internal Server Error)
core.umd.min.js:13 ERROR Error: Uncaught (in promise): Error: (SystemJS) XHR error (500 Internal Server Error) loading http://example.com/app/welcome/welcome.module.js
Error: XHR error (500 Internal Server Error) loading http://example.com/app/welcome/welcome.module.js
And when I insert into browser url http://example.com/app/welcome/welcome.module.js
I have error in console:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
After I click "hard reload" everything works fine. It seems server side works correctly. I can't understand the cause of error.
Lazy loading? SystemJS loads modules incorrectly? Or anything else? How can I resolve that random issue?