1

I've created a sample PWA application using angular 7, everything works fine. But when I installed my PWA in android & tried to open my app in offline mode, I am getting "Can't connect to site". According to angular pwa, even though we are in offline, we should still open the application right ?

Expected result :

Angular pwa in android should open even though we are in offline mode.

Actual result :

Getting Can't connect to site popup

Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73
Vinay Nvd
  • 65
  • 5
  • If you're using a service worker in your Angular PWA app, you can check your app in offline mode with an explicit mentioning of index.html. Here's a related [SO post](https://stackoverflow.com/questions/43029667/angular-service-worker-not-working-when-offline) regarding your issue. – Jessica Rodriguez Jun 10 '19 at 14:47
  • I have the same issue. I am questioning if this is related to my url path, which is /homepage. homepage is a angular route, not a file and I have not configured anything about homepage for the service worker. Could that be causing the issue? – iwhp Oct 02 '19 at 08:42

1 Answers1

0

Assuming you are having the same issue I had, you may be having a service worker issue. The solution that worked for me was manually registering the service worker. In your src/main.ts change the following:

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.error(err));

to

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

I originally found the solution here: https://github.com/angular/angular-cli/issues/13351