Constructor

Route

new Route(input)

Constructor for Route class.

Parameter

input

Object

Example

// Any navigate requests for URLs that start with /path/to/ will match.
const route = new workbox.routing.Route({
  match: ({url, event}) => {
    return event.request.mode === 'navigate' &&
           url.pathname.startsWith('/path/to/');
  },
  handler: ({event}) => {
    // Do something that returns a Promise.<Response>, like:
    return caches.match(event.request);
  },
});

const router = new workbox.routing.Router();
router.registerRoute({route});

Abstract types

handlerCallback

inner

handlerCallback(input) returns Promise containing Response

This is the definition of the handler callback that can be passed into the Route constructor.

The handler callback is called when a request has been matched by a Route and should return a Promise that resolves with a Response.

Parameter

input

Object

Returns

Promise containing Response The response that will fulfill the request.

matchCallback

inner

matchCallback(input) returns (Object or null)

This is the definition of the match callback passed into the Route constructor.

This callback is used to determine if a new fetch event can be served by this Route. Returning a truthy value indicates that this Route can handle this fetch event. Return null if this shouldn't match against the fetch event.

If you do return a truthy value, the object will be passed to the Route's handler (see the Route Constructor).

Parameter

input

Object

Returns

(Object or null) To signify a match, return a truthy value, otherwise return null if the route shouldn't match. If you return an Object with contents it will be passed to the handler in the Route constructor.