首页 > 解决方案 > 使用 react i18n 部署我的 React 应用程序会在 locales.json 上引发 404 错误

问题描述

我已经在 Netlify 上部署了我的 React 应用程序 (CRA),但它在所有 translations.json 文件上给了我 404 错误。它在本地工作,所以我迷路了。

我的 i18n 设置文件如下所示:

import i18n from 'i18next'
import Backend from 'i18next-xhr-backend'
import LanguageDetector from 'i18next-browser-languagedetector'
import { initReactI18next } from 'react-i18next'

export const appLocales = ['en', 'ja', 'nl']

i18n.use(Backend)
    .use(LanguageDetector)
    .use(initReactI18next)
    .init({
        debug: false,
        lng: 'en',
        fallbackLng: 'en',
        whitelist: appLocales,
        interpolation: {
            escapeValue: false
        }
    })

export default i18n

虽然翻译似乎正在工作,但我想知道为什么它首先抛出 404 错误。有人可以帮我吗?

标签: reactjsnetlifyreact-i18next

解决方案


推荐阅读