Unverified Commit 386afcd4 authored by Prateek Choudhary's avatar Prateek Choudhary Committed by GitHub

docs: Update redirects i18n documentation for App Router (#81347)

### What?
Updated the documentation to clarify that App Router requires manual
locale handling through dynamic route segments and middleware, with
examples showing how to implement i18n redirects correctly.

### Why?
The App Router doesn't use the i18n configuration in next.config.js like
the Pages Router does.

Closes NEXT-
Fixes #81227

---------
Co-authored-by: 's avatarJoseph <joseph.chamochumbi@vercel.com>
Co-authored-by: 's avatarJoseph <sephxd1234@gmail.com>
parent 01e1854f
......@@ -250,7 +250,42 @@ module.exports = {
<AppOnly>
When leveraging [`i18n` support](/docs/app/guides/internationalization) with redirects each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the redirect. If `locale: false` is used you must prefix the `source` and `destination` with a locale for it to be matched correctly.
When implementing redirects with internationalization in the App Router, you can include locales in `next.config.js` redirects, but only as hardcoded paths.
For dynamic or per-request locale handling, use [dynamic route segments and middleware](/docs/app/guides/internationalization), which can redirect based on the user's preferred language.
```js filename="next.config.js"
module.exports = {
async redirects() {
return [
{
// Manually handle locale prefixes for App Router
source: '/en/old-path',
destination: '/en/new-path',
permanent: false,
},
{
// Redirect for all locales using a parameter
source: '/:locale/old-path',
destination: '/:locale/new-path',
permanent: false,
},
{
// Redirect from one locale to another
source: '/de/old-path',
destination: '/en/new-path',
permanent: false,
},
{
// Catch-all redirect for multiple locales
source: '/:locale(en|fr|de)/:path*',
destination: '/:locale/new-section/:path*',
permanent: false,
},
]
},
}
```
</AppOnly>
......@@ -258,8 +293,6 @@ When leveraging [`i18n` support](/docs/app/guides/internationalization) with red
When leveraging [`i18n` support](/docs/pages/guides/internationalization) with redirects each `source` and `destination` is automatically prefixed to handle the configured `locales` unless you add `locale: false` to the redirect. If `locale: false` is used you must prefix the `source` and `destination` with a locale for it to be matched correctly.
</PagesOnly>
```js filename="next.config.js"
module.exports = {
i18n: {
......@@ -307,7 +340,9 @@ module.exports = {
}
```
In some rare cases, you might need to assign a custom status code for older HTTP Clients to properly redirect. In these cases, you can use the `statusCode` property instead of the `permanent` property, but not both. To to ensure IE11 compatibility, a `Refresh` header is automatically added for the 308 status code.
</PagesOnly>
In some rare cases, you might need to assign a custom status code for older HTTP Clients to properly redirect. In these cases, you can use the `statusCode` property instead of the `permanent` property, but not both. To ensure IE11 compatibility, a `Refresh` header is automatically added for the 308 status code.
## Other Redirects
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment