Open mabasic opened 1 year ago
I mentioned this in my ticket, but there's a large series of items related to middleware.ts file simply existing and pages router - anyway to get eyes on it Vercel team? Big fan of NextJS, but this behavior is really impacting us.
and more...
Any progress here for Pages Router and middleware.ts? I've seen even more tickets than above recently and this is blocking a big migration of ours.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Data fetching (gS(S)P, getInitialProps), 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/mabasic/nextjs-middleware-catch-all-issue
To Reproduce
Next.js issue with middleware/catch-all/rewrites/getInitialProps when client side navigation occurs
Must be built with
npm run build
and started withnpm run start
for the issue to appear. It works in development mode withnpm run dev
.Reproduction steps
next.config.js
:Existence of
middleware.ts
file. Can be an empty file to reproduce the issue.src/middleware.ts
:Catch-all page route eg.
src/pages/test/[...slugs].js
.Must have
getInitialProps
for this issue to appear. It works when server rendering, but does not work on client side navigation.src/pages/test/[...slugs].tsx
:Issue
Open the browser on
http://localhost:3000/something1/test2
, and click on the link "something2/test2".If you check the console log (in the browser) after a client side navigation event, you will not see
slugs
, but onlyslug
. On server rendering this works properly. You get bothslugs
andslug
in the console.Solution
There are two solutions:
slugs
to the page params (see example bellow)Example:
next.config.js
:Describe the Bug
Catch-all variable is not passed to context query when middleware file is present and when getInitialProps is used, and when a client-side navigation occurs.
Expected Behavior
Catch-all variable should be passed in this scenario.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response