Server side locale always default in dynamic routes when a middleware is present
Problem
Verify canary release - [X] I verified that the issue exists in the latest Next.js canary release Provide environment information [code block] 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/XavierLasierra/next-dynamic-routes-bug To Reproduce 1. Clone repository, install dependencies and start the server 2. Go to the main page with a locale other than the default (ex `/en`) 3. Navigate to a dynamic route using `next/link` 4. The locale on the server side will be always the default one only when doing client navigation Describe the Bug When doing client side navigation to a dynamic route having a `middleware.js` file, the locale will always be the default one. [code block]` - This is not happening for static routes. - This is not happening for dynamic routes with no `middleware.js` file. Expected Behavior The locale will be consistent in dynamic routes. Which browser are you using? (if relevant) Chrome 115.0.5790.170 How are you deploying your application? (if relevant) _No response_
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Server side locale always default in dynamic routes when a middleware is present
Having the same issue when middleware file present. Problem is since v13.4.13. We have multi locale setup. Navigating pages with `next/link` getting 404 page not found. The page is in `en` locale. In middleware `req.nextUrl.locale` is `en`, but in `getStaticProps` the `context.locale` is the default locale - e.g.`de`.
Trust Score
6 verifications
- 1
Having the same issue when middleware file present. Problem is since v13.4.13.
We have multi locale setup. Navigating pages with `next/link` getting 404 page not found. The page is in `en` locale. In middleware `req.nextUrl.locale` is `en`, but in `getStaticProps` the `context.locale` is the default locale - e.g.`de`.
Validation
Resolved in vercel/next.js GitHub issue #54217. Community reactions: 14 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep