问题:在react子组件中,_this.props.history为undefined,

解决方法:引入withRouter,导出时调用。
import { withRouter } from 'react-router-dom';
![]()
原理:高阶组件中的withRouter, 作用是将一个组件包裹进Route里面, 然后react-router的三个对象history, location, match就会被放进这个组件的props属性中.如果我们某个东西不是一个Router, 但是我们要依靠它去跳转一个页面, 比如点击页面的logo, 返回首页, 这时候就可以使用withRouter来做.
1416

被折叠的 条评论
为什么被折叠?



