The Node.js® Website
at main 663 B view raw
1import createMiddleware from 'next-intl/middleware'; 2 3import { availableLocaleCodes, defaultLocale } from '@/next.locales.mjs'; 4 5export default createMiddleware({ 6 // A list of all locales that are supported 7 locales: availableLocaleCodes, 8 9 // Used when no locale matches 10 defaultLocale: defaultLocale.code, 11 12 // Always use a Locale as a prefix for routing 13 localePrefix: 'always', 14 15 // We already have our own way of providing alternate links 16 // generated on `next.dynamic.mjs` 17 alternateLinks: false, 18}); 19 20// We only want the middleware to run on the `/` route 21// to redirect users to their preferred locale 22export const config = { matcher: ['/'] };