workbox-routing. NavigationRoute
NavigationRoute is a helper class to create a Route that matches for browser navigation requests, i.e. requests for HTML pages.
It will only match incoming requests whose mode
is set to navigate
.
You can optionally only apply this route to a subset of navigation requests by using one or both of the blacklist
and whitelist
parameters. If both lists are provided, and there's a navigation to a URL which matches
both, then the blacklist will take precedence and the request will not be matched by this route. The regular expressions in whitelist
and blacklist
are matched against the concatenated
pathname
and search
portions of the requested URL.
To match all navigations, use a whitelist
array containing a RegExp that matches everything, i.e. [/./]
.
Constructor
NavigationRoute
new NavigationRoute(input)
Constructor for NavigationRoute.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
input |
Object Values in
|
- Extends
- Route
Example
// Any navigation requests that match the whitelist (i.e. URLs whose path
// starts with /article/) will be handled with the cache entry for
// app-shell.html.
const route = new workbox.routing.NavigationRoute({
whitelist: [new RegExp('^/article/')],
handler: {handle: () => caches.match('app-shell.html')},
});
const router = new workbox.routing.Router();
router.registerRoute({route});