123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import { assert } from 'workbox-core/_private/assert.js';
- import { logger } from 'workbox-core/_private/logger.js';
- import { Route } from './Route.js';
- import './_version.js';
- class NavigationRoute extends Route {
-
- constructor(handler, { allowlist = [/./], denylist = [] } = {}) {
- if (process.env.NODE_ENV !== 'production') {
- assert.isArrayOfClass(allowlist, RegExp, {
- moduleName: 'workbox-routing',
- className: 'NavigationRoute',
- funcName: 'constructor',
- paramName: 'options.allowlist',
- });
- assert.isArrayOfClass(denylist, RegExp, {
- moduleName: 'workbox-routing',
- className: 'NavigationRoute',
- funcName: 'constructor',
- paramName: 'options.denylist',
- });
- }
- super((options) => this._match(options), handler);
- this._allowlist = allowlist;
- this._denylist = denylist;
- }
-
- _match({ url, request }) {
- if (request && request.mode !== 'navigate') {
- return false;
- }
- const pathnameAndSearch = url.pathname + url.search;
- for (const regExp of this._denylist) {
- if (regExp.test(pathnameAndSearch)) {
- if (process.env.NODE_ENV !== 'production') {
- logger.log(`The navigation route ${pathnameAndSearch} is not ` +
- `being used, since the URL matches this denylist pattern: ` +
- `${regExp}`);
- }
- return false;
- }
- }
- if (this._allowlist.some((regExp) => regExp.test(pathnameAndSearch))) {
- if (process.env.NODE_ENV !== 'production') {
- logger.debug(`The navigation route ${pathnameAndSearch} ` +
- `is being used.`);
- }
- return true;
- }
- if (process.env.NODE_ENV !== 'production') {
- logger.log(`The navigation route ${pathnameAndSearch} is not ` +
- `being used, since the URL being navigated to doesn't ` +
- `match the allowlist.`);
- }
- return false;
- }
- }
- export { NavigationRoute };
|