Didn't make the #ChromeDevSummit this year? Catch all the content (and more!) in the Chrome Dev Summit 2019 playlist on our Chrome Developers YouTube Channel.

Namespace: routing

Classes

Properties

registerNavigationRoute

constant   static

Registers a route that will return a precached file for a navigation request. This is useful for the application shell pattern.

When determining the URL of the precached HTML document, you will likely need to call workbox.precaching.getCacheKeyForURL(originalUrl), to account for the fact that Workbox's precaching naming conventions often results in URL cache keys that contain extra revisioning info.

This method will generate a NavigationRoute and call Router.registerRoute() on a singleton Router instance.

Parameter

cachedAssetUrl

string

The cache key to use for the HTML file.

options

Optional

Object

Values in options have the following properties:

Parameter

cacheName

Optional

string

Cache name to store and retrieve requests. Defaults to precache cache name provided by workbox-core.cacheNames.

blacklist

Optional

Array of RegExp

If any of these patterns match, the route will not handle the request (even if a whitelist entry matches).

whitelist

Optional

Array of RegExp

If any of these patterns match the URL's pathname and search parameter, the route will handle the request (assuming the blacklist doesn't match).

Returns

workbox.routing.NavigationRoute Returns the generated Route.

registerRoute

constant   static

Easily register a RegExp, string, or function with a caching strategy to a singleton Router instance.

This method will generate a Route for you if needed and call Router.registerRoute().

Parameter

capture

(RegExp, string, workbox.routing.Route~matchCallback, or workbox.routing.Route)

If the capture param is a Route, all other arguments will be ignored.

handler

workbox.routing.Route~handlerCallback

A callback function that returns a Promise resulting in a Response.

method

Optional

string

The HTTP method to match the Route against.

Returns

workbox.routing.Route The generated Route(Useful for unregistering).

setCatchHandler

constant   static

If a Route throws an error while handling a request, this handler will be called and given a chance to provide a response.

Parameter

handler

workbox.routing.Route~handlerCallback

A callback function that returns a Promise resulting in a Response.

setDefaultHandler

constant   static

Define a default handler that's called when no routes explicitly match the incoming request.

Without a default handler, unmatched requests will go against the network as if there were no service worker present.

Parameter

handler

workbox.routing.Route~handlerCallback

A callback function that returns a Promise resulting in a Response.