export const nextConfig = { i18n: { locales: ['en', 'fr', 'es'], defaultLocale: 'en', localeDetection: true } }; // User navigates to home page with locale 'fr'
Next.js adds the locale as a sub-path prefix for routing when using sub-path routing. For French locale, the home page URL becomes /fr.
Next.js enables sub-path routing by default when you specify locales and defaultLocale. The localeDetection option controls automatic locale detection but does not disable sub-path routing.
Next.js uses the first path segment to detect the locale when sub-path routing is enabled. Here, '/es/about' means the locale is 'es' (Spanish).
module.exports = { i18n: { locales: ['en', 'fr'], defaultLocale: 'en', localeDetection: true }, trailingSlash: true };
Next.js does not add the locale prefix for the defaultLocale to keep URLs clean. So URLs for 'en' won't have '/en', but URLs for 'fr' should have '/fr'. If '/fr' is missing, it might be a navigation or link issue.
Middleware in Next.js can detect the user's preferred locale and redirect them to the appropriate locale sub-path URL before the page renders, enabling seamless locale routing.