What is withRouter for in react-router-dom?

后端 未结 4 1978
小鲜肉
小鲜肉 2020-12-02 04:56

I\'ve sometimes seen people wrap their components in withRouter when they are exporting them:

import { w         


        
4条回答
  •  借酒劲吻你
    2020-12-02 05:34

    withRouter is a higher-order component that will pass the closest route's to get access to some property as to location and match from the props it can be accessed only if give the component the property located in the component

    
    

    and same the match and location prosperity to be able to change the location and used this.props.history.push it should be provided for each component property must provide but when used WithRouter it can be access to location and match without add property history it can be accessed direction without add property history fro each Route.

提交回复
热议问题