Constructor

Route

new Route(match, handler, method)

Constructor for Route class.

Parameter

match

workbox.routing.Route~matchCallback

A callback function that determines whether the route matches a given fetch event by returning a non-falsy value.

handler

workbox.routing.Route~handlerCallback

A callback function that returns a Promise resolving to a Response.

method

Optional

string

The HTTP method to match the Route against.

Abstract types

handlerCallback

inner

handlerCallback(context) returns Promise containing Response

The "handler" callback is called when a service worker's fetch event has been matched by a Route. This callback should return a Promise that resolves with a Response.

If a value is returned by the match callback it will be passed in as the context.params argument.

Parameter

context

Object

Values in context have the following properties:

Parameter

url

URL

The request's URL.

event

FetchEvent

The service worker's fetch event.

params

Optional

Object

Parameters returned by the Route's match callback function. This will be undefined if nothing was returned.

Returns

Promise containing Response The response that will fulfill the request.

matchCallback

inner

matchCallback(context) returns (Object or null)

The "match" callback is used to determine if a Route should handle a service worker's fetch event. Returning a truthy value means this Route will handle and respond to the event.

Return null if this Route shouldn't match against the fetch event.

Any truthy value returned by this callback will be passed to the Route's handler callback.

Parameter

context

Object

Values in context have the following properties:

Parameter

url

URL

The request's URL.

event

FetchEvent

The service worker's fetch event.

Returns

(Object or null) To signify a match, return anything other than null. Return null if the route shouldn't match. handler.