withRouter 你可以通過 withRouter 高階組件訪問 history 對(duì)象的屬性和最近(UI 結(jié)構(gòu)上靠的最近)的 <Route> 的 match 對(duì)象卿操。當(dāng)組件渲染時(shí)囊陡,withRouter 會(huì)將更新后的 match、location 和 history 傳遞給它肩祥。封裝組件的所有無反應(yīng)的特定靜態(tài)方法和屬性都會(huì)自動(dòng)復(fù)制到 connected 組件。
Component.WrappedComponent 被包裝的組件被公開為返回組件上的靜態(tài)屬性 WrappedComponent庐橙,它可用于隔離測(cè)試組件等等执隧。
wrappedComponentRef: func 一個(gè)將作為 ref 屬性傳遞給包裝組件的函數(shù)
高階組件的使用
image.png
高階組件withRouter工作原理
image.png