Setting service worker to exclude certain urls only

前端 未结 5 901
遥遥无期
遥遥无期 2020-12-05 07:26

I built an app using create react which by default includes a service worker. I want the app to be run anytime someone enters the given url except when they go to /blog/, wh

5条回答
  •  隐瞒了意图╮
    2020-12-05 07:38

    Another way to blacklist URLs, i.e., exclude them from being served from cache, when you're using Workbox can be achieved with workbox.routing.registerNavigationRoute:

    workbox.routing.registerNavigationRoute("/index.html", {
      blacklist: [/^\/api/,/^\/admin/],
    });
    

    The example above demonstrates this for a SPA where all routes are cached and mapped into index.html except for any URL starting with /api or /admin.

提交回复
热议问题