-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Router.query contains _next when using middleware with dynamic routes #43598
Comments
Tracked down to this release: https://github.com/vercel/next.js/releases/tag/v12.2.6-canary.8, likely related PR: #39257 |
I confirm the issue persists, taking the reproduction repo and upgrading to both |
…outes (#48753) Fixes: #43598 This was a tricky one to find! Not sure why more people aren't complaining about this issue, was super annoying in my use case since links had the wrong URL. ## What? This issue only occurred when basepath was defined and middleware and dynamic pages are being used. Example from the reproduction repo mentioned in the issue tagged: <img width="686" alt="Screenshot 2023-04-23 at 9 32 55 PM" src="https://user-images.githubusercontent.com/11258286/233850968-e14f6b49-858b-410e-b8f9-93c90447090a.png"> ## Why? `nextConfig` wasn't passed to `getNextPathnameInfo` function, hence the basePath wasn't removed from a intermediate variable and that trickled down to cause this issue. Added test case based on the issue reproduction repo --------- Co-authored-by: Jimmy Lai <[email protected]>
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area of Next.js is affected? (leave empty if unsure)
Middleware / Edge (API routes, runtime)
Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster
https://github.com/mv-nborrett/middleware-dynamic-routes
To Reproduce
npm run dev
.Describe the Bug
My understanding is that router.query.path should match the path segment matched in the dynamic route. However, when middleware is used, even if that middleware just passes the request through without taking any action, router.query.path displays _next in certain situations. If the middleware is removed (ie, middleware.ts is deleted), router.query.path always displays the correct value.
Expected Behavior
I would expect router.query.path to contain the path segment displayed in the URL. The reason that this is an issue is that we have buttons which use router.query.path as a prefix when linking to pages deeper in the tree. This means that the button sends the user to http://localhost:3000/base/_next/child-page instead of http://localhost:3000/base/default/child-page.
Which browser are you using? (if relevant)
Chrome 107.0.5304.122 (Official Build) (32-bit)
How are you deploying your application? (if relevant)
npm run dev
The text was updated successfully, but these errors were encountered: