如何实施maybeGoToBar
- 根据名称 - 我会显示Foo
组件或Bar
组件而不更改网址?< / p>
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} >