| 1 | import { RouteHandler } from 'workbox-core/types.js';
|
|---|
| 2 | import { Route } from './Route.js';
|
|---|
| 3 | import './_version.js';
|
|---|
| 4 | export interface NavigationRouteMatchOptions {
|
|---|
| 5 | allowlist?: RegExp[];
|
|---|
| 6 | denylist?: RegExp[];
|
|---|
| 7 | }
|
|---|
| 8 | /**
|
|---|
| 9 | * NavigationRoute makes it easy to create a
|
|---|
| 10 | * {@link workbox-routing.Route} that matches for browser
|
|---|
| 11 | * [navigation requests]{@link https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests}.
|
|---|
| 12 | *
|
|---|
| 13 | * It will only match incoming Requests whose
|
|---|
| 14 | * {@link https://fetch.spec.whatwg.org/#concept-request-mode|mode}
|
|---|
| 15 | * is set to `navigate`.
|
|---|
| 16 | *
|
|---|
| 17 | * You can optionally only apply this route to a subset of navigation requests
|
|---|
| 18 | * by using one or both of the `denylist` and `allowlist` parameters.
|
|---|
| 19 | *
|
|---|
| 20 | * @memberof workbox-routing
|
|---|
| 21 | * @extends workbox-routing.Route
|
|---|
| 22 | */
|
|---|
| 23 | declare class NavigationRoute extends Route {
|
|---|
| 24 | private readonly _allowlist;
|
|---|
| 25 | private readonly _denylist;
|
|---|
| 26 | /**
|
|---|
| 27 | * If both `denylist` and `allowlist` are provided, the `denylist` will
|
|---|
| 28 | * take precedence and the request will not match this route.
|
|---|
| 29 | *
|
|---|
| 30 | * The regular expressions in `allowlist` and `denylist`
|
|---|
| 31 | * are matched against the concatenated
|
|---|
| 32 | * [`pathname`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname}
|
|---|
| 33 | * and [`search`]{@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search}
|
|---|
| 34 | * portions of the requested URL.
|
|---|
| 35 | *
|
|---|
| 36 | * *Note*: These RegExps may be evaluated against every destination URL during
|
|---|
| 37 | * a navigation. Avoid using
|
|---|
| 38 | * [complex RegExps](https://github.com/GoogleChrome/workbox/issues/3077),
|
|---|
| 39 | * or else your users may see delays when navigating your site.
|
|---|
| 40 | *
|
|---|
| 41 | * @param {workbox-routing~handlerCallback} handler A callback
|
|---|
| 42 | * function that returns a Promise resulting in a Response.
|
|---|
| 43 | * @param {Object} options
|
|---|
| 44 | * @param {Array<RegExp>} [options.denylist] If any of these patterns match,
|
|---|
| 45 | * the route will not handle the request (even if a allowlist RegExp matches).
|
|---|
| 46 | * @param {Array<RegExp>} [options.allowlist=[/./]] If any of these patterns
|
|---|
| 47 | * match the URL's pathname and search parameter, the route will handle the
|
|---|
| 48 | * request (assuming the denylist doesn't match).
|
|---|
| 49 | */
|
|---|
| 50 | constructor(handler: RouteHandler, { allowlist, denylist }?: NavigationRouteMatchOptions);
|
|---|
| 51 | /**
|
|---|
| 52 | * Routes match handler.
|
|---|
| 53 | *
|
|---|
| 54 | * @param {Object} options
|
|---|
| 55 | * @param {URL} options.url
|
|---|
| 56 | * @param {Request} options.request
|
|---|
| 57 | * @return {boolean}
|
|---|
| 58 | *
|
|---|
| 59 | * @private
|
|---|
| 60 | */
|
|---|
| 61 | private _match;
|
|---|
| 62 | }
|
|---|
| 63 | export { NavigationRoute };
|
|---|