React Router v4 - onEnter


(Imbr) #1

Hello,
I would like to fetch data from the API after EVERY call of (redux LOCATION_CHANGE acction).

<Switch>
  <Route path="/some"/>
  <Route ... />
</Switch>

In older versions of <Route>, we could use the onEnter event to set some promises which retrieved the data.
How to correctly/professionally do it now?

For the moment I have set REDUX SAGA listener for every LOCATION_CHANGE acction. But this solution limits me.

I will be grateful for your help :slight_smile:


(Ihtml5) #2

@imbr you can fetch data in Route render function


(Imbr) #3

Thank you for your answer,
Could you show me some basic example?


(Ihtml5) #4

@imbr

<Switch>
  <Route path="/some" render={({match, location, history} ) => {
      disptach(action);
}}/>
  <Route ... />
</Switch>