从ReactRouter.browserHistory获取以前的路径

时间:2016-11-23 01:27:04

标签: react-router

是否可以从ReactRouter.browserHistory获取前一个路径数和路径值?

3 个答案:

答案 0 :(得分:1)

其实你做不到。 但您可以尝试在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

中找到所有历史记录

答案 1 :(得分:0)

只有我发现重定向到上一页是

this.props.history.goBack();

这是解决我的要求,希望对您有帮助。

答案 2 :(得分:0)

至少在我看来,使用Ionic + React时这种行为是无法预测的。我总是得到路由器的长度在导航时总是大于1,即使它IS正在呈现的第一页也是如此。当用户单击exit时,我正在尝试back button的应用程序,这是首次呈现应用程序时的第一个视图