如何在不更改URL的情况下重定向React Router

时间:2017-03-09 18:16:53

标签: redirect react-router

如何实施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} >

1 个答案:

答案 0 :(得分:0)

您需要使用记忆历史记录。

Link

相关问题