* Registers a route with the router. * * @param {workbox-routing.Route} route The route to register.
(route: Route)
| 419 | * @param {workbox-routing.Route} route The route to register. |
| 420 | */ |
| 421 | registerRoute(route: Route): void { |
| 422 | if (process.env.NODE_ENV !== 'production') { |
| 423 | assert!.isType(route, 'object', { |
| 424 | moduleName: 'workbox-routing', |
| 425 | className: 'Router', |
| 426 | funcName: 'registerRoute', |
| 427 | paramName: 'route', |
| 428 | }); |
| 429 | |
| 430 | assert!.hasMethod(route, 'match', { |
| 431 | moduleName: 'workbox-routing', |
| 432 | className: 'Router', |
| 433 | funcName: 'registerRoute', |
| 434 | paramName: 'route', |
| 435 | }); |
| 436 | |
| 437 | assert!.isType(route.handler, 'object', { |
| 438 | moduleName: 'workbox-routing', |
| 439 | className: 'Router', |
| 440 | funcName: 'registerRoute', |
| 441 | paramName: 'route', |
| 442 | }); |
| 443 | |
| 444 | assert!.hasMethod(route.handler, 'handle', { |
| 445 | moduleName: 'workbox-routing', |
| 446 | className: 'Router', |
| 447 | funcName: 'registerRoute', |
| 448 | paramName: 'route.handler', |
| 449 | }); |
| 450 | |
| 451 | assert!.isType(route.method, 'string', { |
| 452 | moduleName: 'workbox-routing', |
| 453 | className: 'Router', |
| 454 | funcName: 'registerRoute', |
| 455 | paramName: 'route.method', |
| 456 | }); |
| 457 | } |
| 458 | |
| 459 | if (!this._routes.has(route.method)) { |
| 460 | this._routes.set(route.method, []); |
| 461 | } |
| 462 | |
| 463 | // Give precedence to all of the earlier routes by adding this additional |
| 464 | // route to the end of the array. |
| 465 | this._routes.get(route.method)!.push(route); |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * Unregisters a route with the router. |
no test coverage detected