NavigationRoute.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Route } from './Route.js';
  2. import { Handler } from './_types.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. * [Route]{@link module: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. * [`mode`]{@link https://fetch.spec.whatwg.org/#concept-request-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 module:workbox-routing
  21. * @extends module: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. * @param {module:workbox-routing~handlerCallback} handler A callback
  37. * function that returns a Promise resulting in a Response.
  38. * @param {Object} options
  39. * @param {Array<RegExp>} [options.denylist] If any of these patterns match,
  40. * the route will not handle the request (even if a allowlist RegExp matches).
  41. * @param {Array<RegExp>} [options.allowlist=[/./]] If any of these patterns
  42. * match the URL's pathname and search parameter, the route will handle the
  43. * request (assuming the denylist doesn't match).
  44. */
  45. constructor(handler: Handler, { allowlist, denylist }?: NavigationRouteMatchOptions);
  46. /**
  47. * Routes match handler.
  48. *
  49. * @param {Object} options
  50. * @param {URL} options.url
  51. * @param {Request} options.request
  52. * @return {boolean}
  53. *
  54. * @private
  55. */
  56. private _match;
  57. }
  58. export { NavigationRoute };