0

I have a simple app with routing functionality which has a redirection:

const routes: Routes = [
  {
    path: '',
    redirectTo: 'orders',
    pathMatch: 'full'
  },
  {
    path: 'orders',
    component: OrdersComponent
  },
];

The <router-outlet></router-outlet> tag just lies inside the root template (of app.component.ts).

Next, I add the Angular PWA functionality

ng add @angular/pwa

and build my app for production

ng build

When I for the first time open my app through a http server visiting the / path and being redirected to /orders I see this error in dev tools:

Failed to load resource: the server responded with a status of 404 (Not Found) - /orders

The application itself operates smoothly.

It seems that a service worker, which starts its work after the redirection is fulfilled, tries to cache the current page making a request to the current url (/orders) instead of using the root path (/).

Where does this error come from and how can I tell the PWA functionality not to use redirected paths for requests to the server?

Ilya Loskutov
  • 1,967
  • 2
  • 20
  • 34
  • What webserver are you hosting your angular app on? IIS, Apache, Nginx? Also keep in mind that on each deploy you need to increment the `"version"` field in the `ngsw-config.json`, inject `SwUpdate` in your application somewhere, and call `swUpdate.checkForUpdate()` to actually get the newest version – Pieterjan Mar 10 '23 at 11:51

0 Answers0