我正在学习react-router的教程,在那里我遇到了withRouter HOC的主题。为什么在 react-router 库中提供它以及如何使用它?
问问题
347 次
2 回答
1
每当您想要访问match
、history
或location
的对象时都需要它react-router
。对于基本功能,您可以使用Switch
,Route
和Link
,但是如果您想自己实现类似的组件,或者只想在代码中以编程javascript
方式访问路由器功能,则必须分别使用withRouter
or useRouter
。
于 2019-09-09T09:09:51.687 回答
0
withRouter
是一个高阶组件,由react-router-dom
它提供,您可以访问history
,match
以及location
来自用 .props
包裹的特定对象的对象withRouter
。
于 2019-09-09T09:12:57.597 回答