Improve the middleware API for the App Router by using a single object argument and removing the need for as const for the locales:
Before:
const I18nMiddleware = createI18nMiddleware(['en', 'fr'] as const, 'fr')
// With all options:
const I18nMiddleware = createI18nMiddleware(['en', 'fr'] as const, 'fr', {
urlMappingStrategy: 'rewrite',
resolveLocaleFromRequest: request => {
// Do your logic here to resolve the locale
return 'fr'
}
})
After:
const I18nMiddleware = createI18nMiddleware({
locales: ['en', 'fr'],
defaultLocale: 'en'
})
// With all options:
const I18nMiddleware = createI18nMiddleware({
locales: ['en', 'fr'],
defaultLocale: 'en',
urlMappingStrategy: 'rewrite',
resolveLocaleFromRequest: request => {
// Do your logic here to resolve the locale
return 'fr'
}
})
Improved Middleware API
⚠️ BREAKING
Improve the middleware API for the App Router by using a single object argument and removing the need for
as const
for the locales:Before:
After: