Reputation: 41
sorry for my poor English..my question is,when i use <Link/>
to change current route into next route,how i can get previous path in next route's handler? here is some code
// 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 />
)
}
})
thx ~ :-)
Upvotes: 4
Views: 4668
Reputation: 2854
Apparently there's no sanctioned way to do that.
As suggested in this issue, you can save the previous path in router.run
.
var prevPath = null;
router.run(function(Handler, state) {
React.render(<Handler prevPath={prevPath} />, document.body);
prevPath = state.path;
});
Beware, however, that this will point "forward" after using the browser back button.
Upvotes: 1