Unverified Commit b451a7ee authored by Christian Riedel's avatar Christian Riedel Committed by GitHub

[docs/bugfix] fix code example for "Prefixing the Default Locale" - NEXT_LOCALE…

[docs/bugfix] fix code example for "Prefixing the Default Locale" - NEXT_LOCALE cookie usage (#44587)



For this trivial bug(fix) I did not create an issue prior.

The example code changed with #40728 for the "Prefixing the Default Locale" section in the docs has a minor bug, where the NEXT_LOCALE cookie is grabbed and stringified instead of using the value property. This results in `"[object Object]"` and an endless redirection circle.

https://nextjs.org/docs/advanced-features/i18n-routing#prefixing-the-default-locale

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 0f004312
......@@ -183,7 +183,7 @@ export async function middleware(req: NextRequest) {
}
if (req.nextUrl.locale === 'default') {
const locale = req.cookies.get('NEXT_LOCALE') || 'en'
const locale = req.cookies.get('NEXT_LOCALE')?.value || 'en'
return NextResponse.redirect(
new URL(`/${locale}${req.nextUrl.pathname}${req.nextUrl.search}`, req.url)
......
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