Javascript WithRouter无法在componentDidUpdate中工作

Javascript WithRouter无法在componentDidUpdate中工作,javascript,reactjs,react-router,Javascript,Reactjs,React Router,简短的代码如下所示 componentDidUpdate(preProps) { if ( preProps.somethingFeedback === 'whatINeed') { this.props.feedbackReducer() this.props.toggleExitAnimation() this.timeoutHandle = setTimeout(() => { this.props.history.push('path')

简短的代码如下所示

componentDidUpdate(preProps) {
  if ( preProps.somethingFeedback === 'whatINeed') {
    this.props.feedbackReducer()
    this.props.toggleExitAnimation()
    this.timeoutHandle = setTimeout(() => {
      this.props.history.push('path')
    }, 1000)
  }
}
首先,我使用反馈减速器更新当前组件的道具。在componentDidUpdate方法中,我抓住了这个支柱,有条件地分派另外两个减缩器。由于切换动画,我还需要在路由之前超时

该组件使用react redux的connect封装在react路由器的withRouter hoc函数中

我发现原来的代码,反馈减缩功能会自动导致路由。如果我评论feedbackReducer函数,this.props.history.push将不起作用

编辑

下面的代码解决了这个问题

componentDidUpdate(preProps) {
  if ( preProps.somethingFeedback === 'whatINeed') {
    this.props.toggleExitAnimation()
    this.timeoutHandle = setTimeout(() => {
      this.props.feedbackReducer()
      this.props.history.push('path')
    }, 1000)
  }
}

对于我的疏忽,feedbackReducer有一个键反馈来触发路由,因此它应该与history.push一起超时。

您是否检查了超时功能中是否有
this.props.history
可用?我添加了console.log in timeout功能,原始代码不能记录消息,但可以路由。相反,如果我注释feedbackReducer,
console.log(this.props.history)的输出是什么超时函数内部?历史记录显示了正确的路径,路由组件仍然没有更改。好的,我有点困惑。。。需要明确的是:如果您注释掉
this.props.feedbackReducer()
,代码就正常工作了?如果是这样的话,
this.props.feedbackReducer()做什么?你能发布反馈减速器功能的代码吗?