Constructor

Router

new Router()

Initializes a new Router.

Methods

handleRequest

handleRequest(event) returns (Promise containing Response or undefined)

Apply the routing rules to a FetchEvent object to get a Response from an appropriate Route's handler.

Parameter

event

FetchEvent

The event from a service worker's 'fetch' event listener.

Returns

(Promise containing Response or undefined) A promise is returned if a registered route can handle the FetchEvent's request. If there is no matching route and there's no defaultHandler, undefined is returned.

registerRoute

registerRoute(route)

Registers a route with the router.

Parameter

route

workbox.routing.Route

The route to register.

setCatchHandler

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

workbox.routing.Route~handlerCallback

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

setDefaultHandler

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

workbox.routing.Route~handlerCallback

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

unregisterRoute

unregisterRoute(route)

Unregisters a route with the router.

Parameter

route

workbox.routing.Route

The route to unregister.