You can use onEnter prop on Route :
<Route path='posts' onEnter={() => store.dispatch({ type: 'FETCH_POSTS' })} />
In this case, you cannot use the repository in the context of the tree that is inserted into the Provider . You will have to import it and use it directly.
Another option, instead of passing component prop, pass a getComponent :
<Route path='posts' getComponent={(nextState, cb) => { store.dispatch({ type: 'FETCH_POSTS' }); cb(null, PostList); }} />
I canβt say what are the pros and cons for any of these approaches, although I have never used them. I just tried to find a solution that could work for your use case.
Lucas source share