Javascript history.location.replace不是使用react router v4的函数
在redux的组件WillReceiveCeprops中,我可以使用react路由器进行重定向吗?是我干的Javascript history.location.replace不是使用react router v4的函数,javascript,reactjs,redux,Javascript,Reactjs,Redux,在redux的组件WillReceiveCeprops中,我可以使用react路由器进行重定向吗?是我干的 componentWillReceiveProps(nextProps) { if(nextProps.user.isAuthenticated !== this.props.user.isAuthenticated && nextProps.user.isAuthenticated) { console.log(nextProps.history)
componentWillReceiveProps(nextProps) {
if(nextProps.user.isAuthenticated !== this.props.user.isAuthenticated && nextProps.user.isAuthenticated) {
console.log(nextProps.history)
nextProps.history.location.replace('/dashboard')
}
}
但是错误出现在nextrops.history.location.replace('/dashboard')
我也尝试了this.history.location.replace('/dashboard')
但是当我
console.log(nextrops.history)
时,方法就在那里。有什么问题吗?您需要使用这个.props.history.push(“/dashboard”)
历史中的位置对象没有此方法。看看这本书。可在历史记录中直接访问:
nextProps.history.replace('/dashboard')
做一点改变:nextrops
而不是this
@BhojendraNepal这一点都不重要。