GoogleChrome / GoogleChrome/workbox

A question mark at the end of a route causes precached route to not match

Open
#3,291 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
13k
Forks
880
Avg merge
2h 44m
Merged PRs (30d)
8

Description

I'm seeing an issue where navigating to a precached route (using `workbox.precacheAndRoute()`) will fail and display the `navigateFallback` if there is a single `?` without any URL parameters at the end.

That is, navigating to `/some/page` will work, but navigating to `/some/page?` will show the 404 page (`navigateFallback`).

I found that setting `ignoreURLParametersMatching` to `[/.*/]` (i.e. ignore _all_ URL parameters) solves this issue. However, this is awkward. There are no actual URL parameters here, so the only way to match this case is to ignore _all_ URL parameters. It's impossible to only match this case (`?` without any parameters), but not match actual parameters, or only match some parameters as far as I can tell.

**Edit:** Actually, looks like setting this option doesn't work at all, I'm still getting a 404 page.

**Library Affected**:

- workbox-precaching, workbox-build

**Browser & Platform**:

All browsers

**Issue or Feature Request Description**:

Arguably, an empty query (only a `?` at the end of the URL with nothing else) should match precached pages by default. If this isn't possible or there's some edge-case I'm not seeing, it should be possible to configure `ignoreURLParametersMatching` in a way that allows this case to match the precached route, but not other URL parameters.

I'm using `generateSW` right now. Happy to switch to `injectManifest` to address this. Looks like [`urlManipulation`](https://developer.chrome.com/docs/workbox/modules/workbox-precaching#custom_manipulations) is the option I'm looking for? As far as I can tell this isn't available with `generateSW`. Still, the default behavior could be improved here.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.