Skip to content
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

Closed
1 task done
mv-nborrett opened this issue Dec 1, 2022 · 4 comments · Fixed by #48753
Closed
1 task done

Router.query contains _next when using middleware with dynamic routes #43598

mv-nborrett opened this issue Dec 1, 2022 · 4 comments · Fixed by #48753
Labels
Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@mv-nborrett
Copy link

mv-nborrett commented Dec 1, 2022

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 16.17.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.5
  eslint-config-next: 13.0.5
  react: 18.2.0
  react-dom: 18.2.0

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

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

@mv-nborrett mv-nborrett added the bug Issue was opened via the bug report template. label Dec 1, 2022
@balazsorban44 balazsorban44 added kind: bug Middleware Related to Next.js Middleware. Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js. and removed bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware. labels Dec 1, 2022
@balazsorban44
Copy link
Member

Tracked down to this release: https://github.com/vercel/next.js/releases/tag/v12.2.6-canary.8, likely related PR: #39257

@phunanon
Copy link

I confirm the issue persists, taking the reproduction repo and upgrading to both 13.2.4 and 13.2.5-canary.20 (up from 13.0.5).

darshkpatel added a commit to darshkpatel/next.js that referenced this issue Apr 23, 2023
darshkpatel added a commit to darshkpatel/next.js that referenced this issue Apr 23, 2023
@darshkpatel
Copy link
Contributor

This occurs to any dynamic routing page not mentioned in getStaticPaths, matching the matcher in the middleware
still happens in v13.3.1

Screenshot 2023-04-23 at 9 32 55 PM

timneutkens pushed a commit that referenced this issue May 9, 2023
…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]>
@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2023

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Linking and Navigating Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants