React router private routes / redirect not working

后端 未结 9 1226
轮回少年
轮回少年 2020-12-07 16:57

I have slightly adjusted the React Router example for the private routes to play nice with Redux, but no components are rendered when Linking or Redirecting to other \'pages

9条回答
  •  囚心锁ツ
    2020-12-07 17:12

    According to react-router documentation you may just wrap your connect function with withRouter:

    // before
    export default connect(mapStateToProps)(Something)
    
    // after
    import { withRouter } from 'react-router-dom'
    export default withRouter(connect(mapStateToProps)(Something))
    

    This worked for me and my views started to be updated along with routes in this case.

提交回复
热议问题