Unverified Commit e9897803 authored by bestlyg's avatar bestlyg Committed by GitHub

feat(docs): update 14-internationalization.mdx (#62484)

### Improving Documentation

follow the
[example](https://github.com/vercel/next.js/blob/canary/examples/app-dir-i18n-routing/middleware.ts#L53),
it is better to use NextResponse instead of Response.
parent 7d4821de
...@@ -33,6 +33,7 @@ match(languages, locales, defaultLocale) // -> 'en-US' ...@@ -33,6 +33,7 @@ match(languages, locales, defaultLocale) // -> 'en-US'
Routing can be internationalized by either the sub-path (`/fr/products`) or domain (`my-site.fr/products`). With this information, you can now redirect the user based on the locale inside [Middleware](/docs/app/building-your-application/routing/middleware). Routing can be internationalized by either the sub-path (`/fr/products`) or domain (`my-site.fr/products`). With this information, you can now redirect the user based on the locale inside [Middleware](/docs/app/building-your-application/routing/middleware).
```js filename="middleware.js" ```js filename="middleware.js"
import { NextResponse } from "next/server";
let locales = ['en-US', 'nl-NL', 'nl'] let locales = ['en-US', 'nl-NL', 'nl']
...@@ -53,7 +54,7 @@ export function middleware(request) { ...@@ -53,7 +54,7 @@ export function middleware(request) {
request.nextUrl.pathname = `/${locale}${pathname}` request.nextUrl.pathname = `/${locale}${pathname}`
// e.g. incoming request is /products // e.g. incoming request is /products
// The new URL is now /en-US/products // The new URL is now /en-US/products
return Response.redirect(request.nextUrl) return NextResponse.redirect(request.nextUrl)
} }
export const config = { export const config = {
......
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