Redirect by middleware works incorrect for site navigation via Link (with locale change) #52316
Open
1 task done
Labels
bug
Issue was opened via the bug report template.
Linking and Navigating
Related to Next.js linking (e.g., <Link>) and navigation.
stale
The issue has not seen recent activity.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64 Binaries: Node: 16.15.1 npm: 8.11.0 Yarn: 1.22.11 pnpm: N/A Relevant Packages: next: 13.4.9-canary.2 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0 typescript: 4.5.5 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
Internationalization (i18n), 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://codesandbox.io/p/sandbox/laughing-northcutt-wmc65k?file=%2Fpages%2Findex.tsx%3A17%2C11
To Reproduce
Describe the Bug
When you have a Link to the page which should be redirected, you can't use next redirects but you can use middleare to perform redirect.
In next 13.3+ versions if you navigate to a page with locale redirect redirect not happened correctly. In reproduction page will be show correctly (with correct locale) but an url will be incorrect - with wrong locale. Middleware logs a bad data - pathname is "/fr/en/only-en-page" with locale "en"
I have an
Error: Invariant: The detected locale does not match the locale in the query. Expected to find 'en' in '/fr/en/only-en-page' but found 'fr'}
error in my case and url "/fr/en/only-en-page"Expected Behavior
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: