Angular 12 - ngsw-config.json not accessible because of routing

Viewed 101

I had configured my Anngular app with routing, and set a 404 page as described in the documentation:

{ path: '**', loadChildren: () => import('./core/modules/page-not-found/page-not-found.module').then(m => m.PageNotFoundModule) }

I also have configured pwa with the CLI, using the following command:

ng add @angular/pwa

But because of the ** route, I got the following error:

Service worker registration failed with: TypeError: Failed to register a ServiceWorker for scope ('https://app.mydomain.ca/') with script ('https://app.mydomain.ca/ngsw-worker.js'): A bad HTTP response code (404) was received when fetching the script.

Indeed, there is not route to ngsw-worker.js so that makes sense, but how to handle that properly? What is the best practice before I got with exluding routes or using asset folder to place my ngsw-worker.js file ?

Thank you in advance for your help!

0 Answers
Related