javascript - Cannot read property 'push' of undefined react-router
本文介绍了javascript - Cannot read property 'push' of undefined react-router的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
import {Router} from 'react-router'
import createBrowserHistory from 'history/createBrowserHistory'
const history = createBrowserHistory();
const store = rehydrate();
const renderApp = Component => {
render(
<Router history={history}>
<App/>
</Router>,
document.getElementById("root")
);
};
这样写不是会直接注入history吗?
我在App里面用this.props.hist6ory.push()就报错!要从context里面取吗?
解决方案
import {withRouter} from 'react-router'
import {inject, observer} from "mobx-react";
@inject("store")
@withRouter
加个注解
这篇关于javascript - Cannot read property 'push' of undefined react-router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文