0
我如何能实现maybeGoToBar
这样 - 这取决于名字 - 我显示Foo
组件或Bar
组件不改变网址?如何重定向阵营路由器不改变网址
function maybeGoToBar(nextState, replace, callback) {
const name = nextState.params.name;
if (name === "Bob") {
// do something to route to /bar
// but keep showing /bob/foo as the current location
// in the browser address bar
}
callback();
}
<Route path=":name/foo" onEnter={maybeGoToBar} component={Foo} >
<Route path="bar" component={Bar} >
对我来说听起来像你不应该使用路由器来做到这一点。你应该在你的组件中存储一个状态变量(如果需要,它的初始值可以从url中获取),你应该根据状态选择要显示的孩子。 – caesay
[React路由器没有改变URL]可能的重复(http://stackoverflow.com/questions/39721812/react-router-without-changing-url) – Gajus