React-router:如何使用Link获取上一个路径

时间:2015-06-11 11:39:20

标签: reactjs react-router

抱歉我的英语很差..我的问题是,当我使用// route config <Route handler={Route2} name="route2" path="route2" /> // eg: current location is #/route1?key=value <Link to="route2">click to jump to route2</Link> // route2 var Route2 = React.createClass({ componentDidMount: function() { // how i can get previous path '#/route1?key=value' }, render: function() { return ( <div /> ) } }) 将当前路线改为下一条路线时,我如何在下一条路线的处理程序中获得前一条路径?这是一些代码

{{1}}

thx~: - )

1 个答案:

答案 0 :(得分:1)

显然,没有制裁方法可以做到这一点。

根据this issue的建议,您可以将上一个路径保存在router.run

var prevPath = null;
router.run(function(Handler, state) {
  React.render(<Handler prevPath={prevPath} />, document.body);
  prevPath = state.path;
});
然而,请注意,这将指向&#34;转发&#34;使用浏览器后退按钮后。

相关问题