Angular 2 routing sometimes fails after 1-2 minutes of activity in the application
I have a .NET Core + Angular 2 / Typescript / SystemJS app. And use lazy loading to load modules
Here is the 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 went to the control panel page http://example.com/ . Then there is no activity in the web application for about 1-2 minutes and then click on the welcome page. I sometimes have an error (sometimes the 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 paste the url http://example.com/app/welcome/welcome.module.js into the browser
I have an error in the console:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
After I hit "hard reload" everything is fine. The server side seems to be working correctly. I cannot figure out the reason for the error.
Lazy loading? SystemJS loading modules incorrectly? Or something else? How to solve this random problem?
source to share
No one has answered this question yet
Check out similar questions: