Next-Intl 不适用于 Next JS 中的嵌套路由

问题描述 投票:0回答:1

我正在使用

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

中间件.js

import createMiddleware from "next-intl/middleware";

export default createMiddleware({
  locales: ["en", "ka", "ru"],
  defaultLocale: "en",
});

export const config = {
  matcher: ["/", "/(en|ka|ru)/:path*"],
};

i18n.js

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,
  };
});
reactjs middleware next.js13 app-router next-intl
1个回答
0
投票

您应该将 next js 链接替换为 next-intl 链接。 在以前的版本中,有一个用于此目的的组件,但现在他们放弃了它,您必须自己实现它,因此请阅读此内容以了解如何做到这一点: https://next-intl-docs.vercel.app/docs/routing/navigation#link

© www.soinside.com 2019 - 2024. All rights reserved.