diff --git a/docs/advanced-features/i18n-routing.md b/docs/advanced-features/i18n-routing.md index 76837abe110c5..c4ed2f39e0067 100644 --- a/docs/advanced-features/i18n-routing.md +++ b/docs/advanced-features/i18n-routing.md @@ -183,7 +183,11 @@ export async function middleware(req: NextRequest) { } if (req.nextUrl.locale === 'default') { - return NextResponse.redirect(new URL(`/en${req.nextUrl.pathname}`, req.url)) + const locale = req.cookies.get('NEXT_LOCALE') || 'en' + + return NextResponse.redirect( + new URL(`/${locale}${req.nextUrl.pathname}${req.nextUrl.search}`, req.url) + ) } } ```