Angular 6 PWA with Node not working

后端 未结 1 1236
梦谈多话
梦谈多话 2021-01-24 13:02

I have a Angular 6 app that works and registers the SW when served with http-server --port 8080 command as you can see here:

But when I serve the

相关标签:
1条回答
  • 2021-01-24 13:33

    I think this issue is to do with the path that @angular/cli uses when registering the service worker, I have found registering the service worker in main.ts to be more reliable:

    platformBrowserDynamic().bootstrapModule(AppModule).then(() => {
      if ('serviceWorker' in navigator && environment.production) {
        navigator.serviceWorker.register('ngsw-worker.js');
      }
    }).catch(err => console.log(err));
    

    Or, looking at this recent comment you can manually modify the path in app.modules.ts

    -ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production })
    +ServiceWorkerModule.register('.ngsw-worker.js', { enabled: environment.production })
    
    0 讨论(0)
提交回复
热议问题