React Router + Redux - Dispatch an async action on route change?

前端 未结 3 862
温柔的废话
温柔的废话 2021-01-04 22:46

I have a universal react app that\'s using redux and react-router.

I have several routes as follows:

/2016
/2015
/2014
/2013

etc.

3条回答
  •  隐瞒了意图╮
    2021-01-04 23:32

    I prefer to have actions dispatched from the render prop itself:

     {
      this.props.toggleInfoLayer(true);
      return ;
    }} />
    

    This is assuming you are using Redux's mapDispatchToProps argument.

    I tried using the history change event handler as mentioned in the accepted answer, but I found it undesirable to be dispatching actions from a rogue file. One more place I had to think about, when Redux already provides plenty too many.

提交回复
热议问题