不确定其他人是否在遇到此问题之前:

我正在使用:“react-redux”:“5.0.7”,“react-router”:“4.2.0”,“react-router-dom”:“4.2.2”

所以我有一个这样的组件,

shouldComponentUpdate = (nextProps) => {
    // shallow compare each prop and see which one is changed
    console.log(nextProps.history === this.props.history) // true, good
    console.log(nextProps.location === this.props.location) // true, good
    console.log(nextProps.match === this.props.match) // false, what? althought the value inside match is the same? why match is a new object/reference every time?
}

const mapStateToProps = (state, ownProps) => {
  nothing special here, just merge state and ownProps. (Router location/match/history is in ownProps, withRouter inject them in i think)
  at the end of this function i just return the merge of {state, ownProps}
  same issue exists even without my own mapStateToProps
}

export default withRouter(connect(mapStateToProps, mapDispatchToProps)(MyComponent))

每次状态更改时,都会调用mapStateToProps . withRouter注入位置/匹配/历史进入ownProps . 但是由于某些原因,每次调用mapStateToProps时,'match'都是一个新对象,因此它会导致unnessarry重新渲染 .