-
Notifications
You must be signed in to change notification settings - Fork 29.5k
Description
Verify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT Mon, 21 Mar 2022 22:59:40 +0000
Binaries:
Node: 16.13.1
npm: 8.1.2
Yarn: 1.22.17
pnpm: N/A
Relevant packages:
next: 12.1.3-canary.0
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
next start
Describe the Bug
If you have an optional catch-all route and use rewrites to convert query parameters into route parameters, links that have those query parameters don't automatically prefetch the props json even when the json is pregenerated at built time.
Expected Behavior
Prefetch and client-side navigation should work for links/routes with query params the same way as for any other internal link. No page reload, etc.
To Reproduce
I have prepared a minimal repository where the issue is reproduced. https://github.com/dklymenk/next-query-rewrite-router-issue
See my last commit to get the idea of what it takes to reproduce the issue starting from a clean template.
Here are some must-haves
- Delete the default index.tsx page.
- Create an optional catch-all page file
[[...slug]]
to catch our potential parameters. - Add
getStaticPaths
andgetStaticProps
to enable SSG. - Add some links with query params.
- Make sure you render the query param props on the page.
- Add a rewrite to
next.config.js
to transform query params into route params/?s=query1
to/query1
, etc.
yarn build
, yarn start
and go to localhost:3000.
You can open dev tools on the network to see that there is no prefetch happening and if you click on any of the links with query params the page will reload (no client-side navigation).
Interestingly enough, if you remove the /
on the href
, the preload works (you can see json preloaded on network tab), but clicking on the link seems to load only the index.json
(props for the case with no query params).