在redux的componentWillRecevieceProps中,我可以使用React Router重定向吗?我做了这个

componentWillReceiveProps(nextProps) {
    if(nextProps.user.isAuthenticated !== this.props.user.isAuthenticated && nextProps.user.isAuthenticated) {
        console.log(nextProps.history)
        nextProps.history.location.replace('/dashboard')
    }
  }


但是错误在nextProps.history.location.replace('/dashboard')上,我也尝试过this.history.location.replace('/dashboard')

但是当我console.log(nextprops.history)时,方法就在那里。有什么问题?

最佳答案

您需要使用this.props.history.push('/dashboard')

10-07 13:58