Open ValenCassa opened 1 year ago
We tried to implement CSP through middleware and bumped into the exact same issue. For now we did CSP in a hacky way so hopefully this issue can be solved so we can use the preferred way using middleware again.
Curious of the response from Next
Same issue. I have a middleware for securing unauthorized routes + handle some redirects.
Now I was trying to implement a basic modal opening logic (without client-side components) based on usage of Link with "href" that appends open
searchParam, and "as" prop that masks the url so that searchParam is not visible in the browser's address bar.
However, this issue prevents to implement that basic scenario :(
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 thehref
and mask the URL based on theas
prop.Verify canary release
Provide environment information
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.