gpt4 book ai didi

javascript - history.location.replace 不是使用 react-router v4 的函数

转载 作者:行者123 更新时间:2023-11-30 20:32:33 25 4
gpt4 key购买 nike

在 redux 的 componentWillRecevieceProps 中,我可以使用 React 路由器进行重定向吗?我这样做了

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) 时,方法就在那里。有什么问题?

最佳答案

location history 中的对象没有这个方法。查看documentation .它可以在 history 上直接访问:

nextProps.history.replace('/dashboard')

关于javascript - history.location.replace 不是使用 react-router v4 的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50185801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com