NextJs dynamic path variables do not appear in router.query on initial page load, when basePath is changed and middleware exists #52051
Labels
bug
Issue was opened via the bug report template.
Linking and Navigating
Related to Next.js linking (e.g., <Link>) and navigation.
Runtime
Related to Node.js or Edge Runtime with Next.js.
stale
The issue has not seen recent activity.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/tasfik007/subpath-test
To Reproduce
Describe the Bug
I have a NextJS application, recently I changed the basePath of my application in next.config.js file just added the basePath key with my desired path.
After doing that I noticed dynamic path variables that were passed through slugs (e.g. /something/[id].js) are not getting loaded initially in next's router.query (in this case id), but after a full page reload it appears perfectly. Surprisingly the variables were also accessible in the getServerSideProp's context.
Now this only happens if I have a middleware file (middleware.js) in my project. This issue happens even if I do nothing in the middleware.
Expected Behavior
Dynamic variables that are passed through the slugs should be loaded in router.query first time user loaded on the page.
Which browser are you using? (if relevant)
Firefox Browser - 114.0.2 (64-bit)
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: