@angular/service-worker not working when offline

后端 未结 2 1870
陌清茗
陌清茗 2020-12-19 14:03

I never got the service worker from Angular Mobile Team to work properly and at this point I guess I forgot to enable something, because it never worked since the initial re

相关标签:
2条回答
  • 2020-12-19 14:27

    With Maxim's help, I followed the same path as asking person, managed to add offline capability to the existing static web and deploy it on Firebase. The custom manifest on root folder should look like below, they will eventually be merged with autogenerated manifest:

    {
      "routing": {
        "index": "/index.html",
        "routes": {
          "/": {
            "prefix": false
          },
          "/home": {
            "prefix": false
          },
          "/work": { // any routes starting with '/work'
            "prefix": true
          }
        }
      },
      "external": {
        "urls": [
          {
            "url": "https://fonts.googleapis.com/css?family=Quicksand"
          }
        ]
      }
    }
    
    0 讨论(0)
  • 2020-12-19 14:45

    You have to test your app in offline mode with an explicit mentioning of index.html. I checked https://test-service-worker-97321.firebaseapp.com/index.html - it works fine.

    If you wish your app to work in offline without index document mentioned (and for all other routes), you have to set up route redirection

    See the example. This custom ngsw-manifest.json will be merged with auto-generated one during the build.

    0 讨论(0)
提交回复
热议问题