如何从匹配路由(v4)中的BrowserRouter访问操作和历史记录?

时间:2016-09-22 16:06:05

标签: react-router

我正在使用React Router v4并使用BrowserRouter。

enter image description here

此屏幕截图显示BrowserRouter的道具有action="POP"

enter image description here

但是,当我的路线与上面的屏幕截图相匹配时,RegisterMatch或MatchProvider没有通过道具接收动作,历史记录等。

我通过https://github.com/ReactTraining/react-router/blob/v4/website/components/FakeBrowser/index.js#L96看到可能需要注入这些道具,但我无法理解它或让它起作用。

1 个答案:

答案 0 :(得分:0)

<Router />与历史道具使用或<BrowserRouter />使用basename道具解决此问题。 例如<Router history={history}>

<BrowserRouter>忽略历史道具。要使用自定义历史记录,请输入'+       '使用import { Router }代替import { BrowserRouter as Router }

相关问题