为什么 react-router 组件道具不包括历史?

Why are the react-router component props not including history?

我很喜欢 v4,但在 4.1.2 中,这让我在使用浏览器路由器时总是犯错误:

通过 Route 组件中的一个组件,我传入了这些道具:{computedMatch, location, path} 尽管 documentation 告诉我期望 {match, location, history} 这是我通过哈希路由器得到的。

要获取传入的历史记录,我必须使用感觉非常笨重的 withRouter 包装器,因为相关组件是 Route 组件的组件道具。

文档对我来说很合适。这是一个错误吗?

如果您使用 Route as

,您可以访问 {match, location, history}
<Route path="/" component={myComponent} 

在上面的代码中,您可以在 myComponent 中访问匹配位置和历史记录。

否则你必须使用 withRouter