Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pages with URL parameters go straight to the 404 page / navigation fallback #653

Open
MoritzLost opened this issue Jan 26, 2024 · 0 comments

Comments

@MoritzLost
Copy link

MoritzLost commented Jan 26, 2024

I'm seeing an issue where a GET request to a page with any URL parameters (or even just a ? at the end) will go straight to the 404 page (or navigateFallback page) instead of displaying the actual page.

Visiting a page with URL parameters in a new tab works, as does a full reload. But clicking on a link to any page with a URL parameter (or manually appending ? to any route in the URL while the page is open, or submitting a form with method GET) goes straight to the 404 page.

Two questions regarding this behaviour:

  1. According to the documentation on precaching, it should use a CacheFirst strategy but fallback to a network request if it doesn't find a match. Apparently workbox doesn't like to serve precached pages if the URL contains parameters (which, ok, fair enough), but why does it fall back to the 404 page instead of a network request, as the documentation claims it should?
  2. Can I configure workbox to use the precached asset even if there are some URL parameters, so that /path/to/page is used when navigating to /path/to/page? through a link on the site?
    Edit: Never mind the second question, I found ignoreURLParametersMatching. It's awkward when trying to ignore a single question mark, but I guess that's a workbox issue, opened another issue here: A question mark at the end of a route causes precached route to not match GoogleChrome/workbox#3291

Here's my config (I'm using the Astro integration, but I don't think this is relevant here):

import { defineConfig } from 'astro/config';
import AstroPWA from '@vite-pwa/astro';
import manifest from './src/data/manifest.js';

export default defineConfig({
    integrations: [
        AstroPWA({
            manifest,
            injectRegister: null,
            registerType: 'autoUpdate',
            workbox: {
                globPatterns: ['**/*'],
                navigateFallback: '/404',
            },
            experimental: {
                directoryAndTrailingSlashHandler: true,
            },
        }),
    ],
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant