Classes

Methods

registerNavigationRoute

static

registerNavigationRoute(cachedAssetUrl, options) returns workbox.routing.NavigationRoute

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

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

Parameter

cachedAssetUrl

string

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

static

registerRoute(capture, handler, method) returns workbox.routing.Route

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

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

static

setCatchHandler(handler)

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

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

setDefaultHandler

static

setDefaultHandler(handler)

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

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

unregisterRoute

static

unregisterRoute(route)

Unregisters a route with the router.

Parameter

route

The route to unregister.