下面的代码试图在我想要翻译的react项目中使用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语句,它返回一个具有options属性的明确定义的options对象。不知道该怎么做。
我已经将属性移动到特定的组件中,以防它与路由器功能不兼容,并且发生了同样的问题。
更新
问题在i18n组件中。
i18n
.use(LanguageDetector)
.use(Backend)
.init({ ... })被更改为
i18n
.use(LanguageDetector)
.use(Backend)
.use(reactI18nextModule)
.init({ ... })这个问题就解决了。
发布于 2018-07-13 21:44:32
我在缺少.use(reactI18NextModule)部分的更新中添加了答案。
https://stackoverflow.com/questions/51330220
复制相似问题