react中子组件取不到this.props.history

之前写react的时候发现被react-redux的connect包裹的子组件取不到this.props.history这个对象,可是我又的确需要这个对象怎么办?

 

解决办法也很简单,首先你需要这个

import PropTypes from 'prop-types'

然后

 

你的组件.contextTypes = {
  router: PropTypes.object.isRequired
}

然后你就可以取到了

console.log(this.context)

react中子组件取不到this.props.history

转载:https://blog.****.net/sanstu/article/details/80080002