【问题标题】:Cannot read property options on undefined with React and react-i18next无法使用 React 和 react-i18next 读取未定义的属性选项
【发布时间】:2018-07-13 17:32:54
【问题描述】:

我有以下代码试图在我想要翻译的反应项目中使用 i18next。

但是在调用应用程序时,我收到一个错误,即在 I18n 组件中出现 TypeError: Cannot read property 'options' of undefined

// i18n components
import i18n from "/modules/ui/i18n";s
import { I18n } from 'react-i18next';
console.log(i18n);
export const renderRoutes = () => (
  <I18n>
    {
      (t, { i18n }) => (
        <Router history={browserHistory}>
          <Switch>
            <Route exact path="/" component={LandingPage} />
          </Switch>
        </Router>
      )
    }
  </I18n>
);

我添加了 log 语句,它返回一个明确定义的 i18n 对象和 options 属性。不知道该怎么办。

我已将该属性移动到特定组件中,以防它与路由器功能不兼容并且发生相同的问题。

更新

问题出在 i18n 组件中。

i18n
  .use(LanguageDetector)
  .use(Backend)
  .init({ ... })

改为

i18n
  .use(LanguageDetector)
  .use(Backend)
  .use(reactI18nextModule)
  .init({ ... })

问题解决了。

【问题讨论】:

  • 你能改成这个(t, { i18n, t, ready })吗?
  • 我最终面临这个问题。你能帮帮我吗

标签: reactjs i18next react-i18next


【解决方案1】:

我在缺少.use(reactI18NextModule) 部分的更新中添加了答案。

【讨论】:

    猜你喜欢
    • 2021-10-15
    • 1970-01-01
    • 2019-09-17
    • 2019-04-09
    • 2020-10-10
    • 2019-02-15
    • 2020-07-23
    • 2019-07-22
    • 2018-12-05
    相关资源
    最近更新 更多