当前位置 : 主页 > 网页制作 > React >

react-router – 从ReactRouter.browserHistory获取以前的路径

来源:互联网 收集:自由互联 发布时间:2021-06-15
是否有可能从ReactRouter.browserHistory获取以前的路径数和路径值? 其实你做不到. 但您可以尝试在browserHistory状态下存储列表,并在重定向时在其中推送新路径. let history = this.props.location.s
是否有可能从ReactRouter.browserHistory获取以前的路径数和路径值? 其实你做不到.
但您可以尝试在browserHistory状态下存储列表,并在重定向时在其中推送新路径.

let history = this.props.location.state.history;
history.push(this.props.location.pathname)
browserHistory.push({
    pathname: '/yourpath',
    state: { history: history }
})

通过这种方式,您应该在this.props.location.state.history中找到所有历史记录

网友评论