Description
I'm submitting a...
[x] Bug report
Minimal reproduction of the problem with instructions
ng new sw --service-worker --routing
cd sw
ng g c home
ng g c about
- Edit
app-routing.module.ts
to add the routes for the 2 components we've just created:
// ...
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'about', component: AboutComponent }
];
// ...
ng build --prod
npm install -g http-server
(you can use any server to test this, if you already prefer another one)http-server dist
- Access
localhost:8080
(8080 is the default port that http-server uses at the time of reporting this issue) - Access
localhost:8080/about
- Stop the server
- Now try reloading the app while on the
/about
route (if it works the first time, try refreshing a few more times or wait a little before trying again). The browser will display the message:
This page isn’t working
localhost took too long to respond.
HTTP ERROR 504
(With Universal/SSR, it stops working right away, most of the time with the first refresh after stopping the server, no matter the route - and the issue is not the hash in the generated ngsw.json, because I regenerate that at the end of the build process).
Now, if you start the server again, loading the app on the /about
route works (even though http-server is not SPA friendly, it doesn't redirect all requests to index.html), but the service worker kicks in.
Initially I noticed this behavior on a Universal app, doing server side rendering (following the universal-starter repo). So this is not a http-server "not being SPA friendly" issue.
I only used http-server to reproduce it because I wanted to keep the reproduction process as fast as possible, without introducing server side rendering.
The CLI version used (1.6.4) initializes the app with Angular 5.1.0, but I've also tested on 5.2.1. I've skipped mentioning this step above because it happens regardless of the Angular version (at least on >= 5.1.0
, haven't tested with older versions).
Environment
Angular CLI: 1.6.4
Node: 8.9.4
OS: win32 x64
Angular: 5.2.1
Browser:
I've only tested on:
- [x] Chrome (desktop) version 63.0.3239.132
- [x] Chrome (desktop) version 65.0.3323.2 (canary)