我正在使用
next-intl
进行国际化。我已按照此处的安装说明进行操作。这在索引/主页上按预期工作,但是,当我尝试导航到 /register 时,它会忽略区域设置,从而返回 not-found.jsx
我使用
<Link href={"/register"}>
进行导航。
src
|-- app
| |-- [locale]
| |-- (public)
| |-- layout.jsx
| |-- page.jsx
| |-- not-found.jsx
| |-- register
| |-- page.jsx
|-- middleware.js
|-- i18n.js
import createMiddleware from "next-intl/middleware";
export default createMiddleware({
locales: ["en", "ka", "ru"],
defaultLocale: "en",
});
export const config = {
matcher: ["/", "/(en|ka|ru)/:path*"],
};
import { notFound } from "next/navigation";
import { getRequestConfig } from "next-intl/server";
const locales = ["en", "ka", "ru"];
export default getRequestConfig(async ({ locale }) => {
if (!locales.includes(locale)) notFound();
return {
messages: (await import(`../messages/${locale}.json`)).default,
};
});
您应该将 next js 链接替换为 next-intl 链接。 在以前的版本中,有一个用于此目的的组件,但现在他们放弃了它,您必须自己实现它,因此请阅读此内容以了解如何做到这一点: https://next-intl-docs.vercel.app/docs/routing/navigation#link