react獲取當前頁面的url參數

react獲取當前頁面的url參數,必須在url路由對應的組件上獲取,在子組件上獲取不到,爲undefined,獲取形如  /news/:id  的後面的參數 id

this.props.match.params.id

獲取形如 /news?id="abc"的  ?id="abc"  部分,

this.props.location.search
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章