I'm using workbox with webpack to generate a service worker.
With the following code in webpack.config.js
:
new WorkboxPlugin.InjectManifest({
swSrc: "./src/sw.js"
}),
a service worker is generated nicely.
In ./src/sw.js
, I have:
workbox.precaching.precacheAndRoute(self.__precacheManifest || []);
And all of my assets are precached nicely.
However, I have a single page application and I noticed that when refreshing the page while offline from a non-homepage route, the service worker doesn't respond. For example, when refreshing /page1
while offline doesn't work, but refreshing /
does work.
How can I configure workbox to use a runtime strategy that uses /index.html
as a fallback for HTML requests?
Note
Doing something like this:
new WorkboxPlugin.InjectManifest({
swSrc: "./src/sw.js",
navigationFallback: "/index.html"
})
does not work since navigationFallback
is not a valid option in it's above usage.
{ message: '"navigationFallback" is not a supported parameter.'