尝试访问 Next.js 应用程序的任何页面时,我都遇到了 404 问题。
当没有localeSubpaths
提供配置时,应用程序可以正常工作。
实施localeSubpaths
配置(next.config.js)后:
const localeSubpaths = {
en: "en",
"de-DE": "de-DE",
fr: "fr"
};
应用程序不再工作。
每次我尝试访问主根目录/
或任何语言环境页面fr
时,de-DE
浏览器都会显示 404 错误页面(自定义 Next.js 错误页面)。此页面包含一些可以正常工作的翻译内容。
页面还包含指向/
主页的链接。当我通过单击链接导航到主页时 - >主页正确加载(包括相关翻译)
i18n.tsx
配置文件:
import NextI18Next from "next-i18next";
import getConfig from "next/config";
import path from "path";
const { publicRuntimeConfig } = getConfig();
const { localeSubpaths } = publicRuntimeConfig;
const NextI18NextInstance = new NextI18Next({
defaultLanguage: "en",
ns: ["common"],
defaultNS: "common",
otherLanguages: ["de-DE", "de-CH", "fr"],
strictMode: false,
localeSubpaths,
localePath: path.resolve("./public/static/locales")
});
export default NextI18NextInstance;
const {
appWithTranslation,
i18n,
Link,
withTranslation,
Router
} = NextI18NextInstance;
export { appWithTranslation, i18n, Link, withTranslation, Router };