[Pages Router] - Middleware breaks URL masking #55208
Labels
bug
Issue was opened via the bug report template.
Navigation
Related to Next.js linking (e.g., <Link>) and navigation.
Runtime
Related to Node.js or Edge Runtime with Next.js.
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/github/ValenCassa/bug-next/main?file=/middleware.ts:1,1
To Reproduce
Current vs. Expected behavior
Current behavior:
When using middleware, the link redirects you to whatever the
as
prop has been set to instead of browsing to thehref
and masking the URL.Expected behavior:
The link should should browse to the
href
and mask the URL based on theas
prop.Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:40:17 PDT 2023; root:xnu-8796.121.2~3/RELEASE_ARM64_T8112 Binaries: Node: 20.5.0 npm: 9.8.0 Yarn: N/A pnpm: N/A Relevant Packages: next: 13.4.20-canary.23 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)
Additional context
I spent several hours trying to debug what was causing the issue and was going crazy. It seems the
nextUrl
from the request object is returning the pathname as/test/1?id=1
, so it's actually appending both whatever you're using for theas
prop and thehref
. I tried setting the pathname manually too with no success.The text was updated successfully, but these errors were encountered: