我目前正在利用Next.js (v13.5.4)和next-intl (v3.0.0-beta.19)进行国际化.我的目标是将区域设置的URL struct 从en-GB格式修改为en/UK格式.
我已经使用应用程序路由设置了Next,并在server component guide之后初始化了Next-intl.
下面是我在next.config.js中设置URL重写的try :
/** @type {import('next').NextConfig} */
const nextConfig = {
async rewrites() {
return {
beforeFiles: [
{
source: "/en/uk/:path*",
destination: "/en-GB/:path*",
}
]
}
},
}
module.exports = withNextIntl(nextConfig);
使用此配置,可以按预期导航到http://localhost:3000/en-GB个功能.然而,访问http://localhost:3000/en/uk会重定向到http://localhost:3000/en-GB/en/uk(其中en-GB是我最后访问的区域设置).
关于更多的背景,这是我的中间件:
import createMiddleware from 'next-intl/middleware';
export default createMiddleware({
locales: ['de-DE', 'en-GB'],
defaultLocale: ''
});
export const config = {
matcher: ['/((?!api|_next|_vercel|.*\\..*).*)']
};
Attempts at Resolving:个
- 从重写配置中删除了
beforeFiles
段. - 在我的配置中包含了
locale: false
. - 将中间件中的匹配器调整为
matcher: ['/((?!api|en/uk|_next|_vercel|.*\\..*).*)']
,导致错误:Error: Unable to find next-intl locale, have you configured the middleware.
任何见解、替代解决方案或建议都将不胜感激.