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