connect and withRouter issue

后端 未结 4 1184
南笙
南笙 2021-01-31 16:42

I am using Redux and React for my project. I have some Routes in App.js. I also use the connect function in react-redux in my project. To prevent update blocking issue, I usuall

相关标签:
4条回答
  • 2021-01-31 17:24

    You can do it in two ways,

    Proper Way:

    withRouter(connect(mapStateToProps, mapDispatchToAction)(App));
    

    with this, you will able to get withRouter props like history, match etc.. in mapStateToProps.

    2nd way:

    connect(mapStateToProps, mapDispatchToAction)(withRouter(App));
    

    using this, you won't be able to get the withRouter props

    0 讨论(0)
  • 2021-01-31 17:36

    If someone still has the issue then plz follow this one

    const ShowTheLocationWithRouter = withRouter(Login);
    
    export default connect(mapStateToProps, mapDispatchToProps)(ShowTheLocationWithRouter);
    
    0 讨论(0)
  • 2021-01-31 17:44

    You can use it with the method compose from redux library.

    export default compose(
      withRouter,
      connect(mapStateToProps, mapDispatchToProps)
    )(App);
    
    0 讨论(0)
  • 2021-01-31 17:45

    Could you refer to this https://reacttraining.com/react-router/core/api/withRouter, it clearly says that it doesn't work the other way around

    0 讨论(0)
提交回复
热议问题