[Middleware] Locale in NextResponse.rewrite(...) path ignored for dynamic routes when basepath is set and skipMiddlewareUrlNormalize is true #65746
Labels
bug
Issue was opened via the bug report template.
Middleware
Related to Next.js Middleware
Pages Router
Related to Pages Router.
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/localized-slugs-y6fgq8
To Reproduce
Set the following in
next.config.js
to add basepath, enable path based localization, and to setskipMiddlewareUrlNormalize
totrue
.Next create middleware with a rewrite to a different
locale
(I've setup the middleware here to read a query param to override the locale):Next create a dynamic page such as
pages/test/[slug].tsx
, and print out the locale:Go to that page with the
lang
param set to a different locale:/basepath/test/dynamic?lang=fr
, you'll see that the redirect url logs correctly as/basepath/fr/test/dynamic
, but the page loads with the router reportingen-US
as the local.Try these same steps for a non dynamic route, and you'll see that it does work in that case.
Pinning to
~13.3.0
fixes the issue, but no newer version resolves the issue.Current vs. Expected behavior
I expect dynamic routes to respect rewrites the same as non-dynamic routes, where currently in the above scenario, that is not the case.
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Available memory (MB): 8198 Available CPU cores: 4 Binaries: Node: 20.11.1 npm: 10.2.4 Yarn: 1.22.19 pnpm: 8.15.4 Relevant Packages: next: 14.2.3 // Latest available version is detected (14.2.3). eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 5.3.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Middleware, Pages Router
Which stage(s) are affected? (Select all that apply)
next dev (local), next build (local), next start (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: