Skip to content

RegExpRoute ​

Class @vite-pwa/workbox-swkit/routing

RegExpRoute makes it easy to create a regular expression based workbox-routing.Route.

For same-origin requests the RegExp only needs to match part of the URL. For requests against third-party servers, you must define a RegExp that matches the start of the URL.

Constructor ​

ts
new RegExpRoute(regExp: RegExp, handler: RouteHandler, method?: HTTPMethod)

If the regular expression contains [capture groups]https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references, the captured values will be passed to the workbox-routing~handlerCallback params argument.

Parameters

  • regExp – The regular expression to match against URLs.

  • handler – A callback function that returns a Promise resulting in a Response.

  • method – The HTTP method to match the Route against.

Properties ​

PropertyTypeDefaultDescription
catchHandler?RouteHandlerObject
handlerRouteHandlerObject
matchRouteMatchCallback
methodHTTPMethod

Methods ​

setCatchHandler() ​

ts
setCatchHandler(handler: RouteHandler): void

Parameters

  • handler – A callback function that returns a Promise resolving to a Response

Released under the MIT License.