vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.79k stars 26.95k forks source link

Middleware rewrite unexpectedly adds query parameter #40991

Open luukdv opened 2 years ago

luukdv commented 2 years ago

Verify canary release

Provide environment information

Binaries:
  Node: 14.20.0
  npm: 6.14.17
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.1-canary.0
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Describe the Bug

When using version 12.2 or higher, rewrites from middleware will add a query parameter when linking to a dynamic route. It doesn't add the parameter when visiting a url directly.

For a dynamic route that's defined as /pages/[...page].js, the parameter that's added will be ?page=….

Expected Behavior

No query parameter is added; client-side navigations work the same as server-side page loads.

Link to reproduction

https://github.com/luukdv/next-bug-2

To Reproduce

luukdv commented 2 years ago

Updated the reproduction repository to use Next 13.

fakhir-shad commented 1 year ago

I am experiencing the same issue using nextJS 13.4.3. Any solution?

stevenrojasv21 commented 1 year ago

I found a workaround to "fix" this issue: setting the target property of the Link component to any value different from _self (understanding what each value means and what behavior we will expect).

MilanDeruelle commented 6 months ago

Any updates on this? Quite an annoying issue, I don't feel like the whole NextRequest/NextResponse logic is well documented, I can barely figure how it changes the "flow" or find any documentation on things like "ResponseInit", as well as the response object itself and what I can modify on it.