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 invoked whenever a Router matches a URL to a Route via its match callback. This callback should return a Promise that resolves with a Response.

If a non-empty array or object is returned by the match callback it will be passed in as the handler's context.params argument.

Parameter

context

Object

Values in context have the following properties:

Parameter

url

URL

The URL that matched.

request

Optional

FetchEvent

The corresponding request, if available.

event

Optional

FetchEvent

The corresponding event that triggered the request, if available.

params

Optional

Object

Array or Object parameters returned by the Route's match callback. This will be undefined if an empty array or object were returned.

Returns

Promise containing Response The response that will fulfill the request.

matchCallback

inner

matchCallback(context) returns any type

The "match" callback is used to determine if a Route should apply for a particular URL. When matching occurs in response to a fetch event from the client, the event and request objects are supplied in addition to the URL. However, since the match callback can be invoked outside of a fetch event, matching logic should not assume the event or request objects will always be available (unlike URL, which is always available). If the match callback returns a truthy value, the matching route's handler callback will be invoked immediately. If the value returned is a non-empty array or object, that value will be set on the handler's context.params argument.

Parameter

context

Object

Values in context have the following properties:

Parameter

url

URL

The request's URL.

request

Optional

FetchEvent

The corresponding request, if available.

event

Optional

FetchEvent

The corresponding event that triggered the request, if available.

Returns

any type To signify a match, return a truthy value.