0
使用react-router v4,我应该如何获取当前的抽象路径。例如,当使用withRouter(...)
时,我可以访问this.props.location
,但是当我想要students/:id
等时,这会给出/students/19
等等。此功能对于日志记录工具而言是期望的。如何访问react-router v4中的抽象当前路径
我该如何做到这一点?
使用react-router v4,我应该如何获取当前的抽象路径。例如,当使用withRouter(...)
时,我可以访问this.props.location
,但是当我想要students/:id
等时,这会给出/students/19
等等。此功能对于日志记录工具而言是期望的。如何访问react-router v4中的抽象当前路径
我该如何做到这一点?
使用this.props.match.path
。我相信这就是你需要的。
按照[React Router](https://reacttraining.com/react-router/web/example/url-params)中的说明使用'this.props.match.id'。你是这个意思吗? –
这是返回undefined为我。我想要抽象网址的字符串,而不是查询的内容。就像我访问'/ item/5678'页面一样,我想从字面上得到'/ item /:id',这样我就可以在记录中记录这个抽象路径 – Connorelsea