First of all , I want to say that there - this discussion around the topic of receiving data using response-router onEnter catch on if this is really good practice, however, it is somehow like this:
You can transfer the reduction shop to the Router . Let there be your root component where the Router installed:
... import routes from 'routes-location'; class Root extends React.Component { render() { const { store, history } = this.props; return ( <Provider store={store}> <Router history={history}> { routes(store) } </Router> </Provider> ); } } ...
And your routes will look something like this:
import ... ... const fetchData = (store) => { return (nextState, transition, callback) => { const { dispatch, getState } = store; const { loaded } = getState().myCoolReduxStore; // loaded is a key from my store that I put true when data has loaded if (!loaded) { // no data, dispatch action to get it dispatch(getDataAction()) .then((data) => { callback(); }) .catch((error) => { // maybe it failed because of 403 forbitten, we can use tranition to redirect. // what in state will come as props to the component `/forbitten` will mount. transition({ pathname: '/forbitten', state: { error: error } }); callback(); }); } else { // we already have the data loaded, let router continue its transition to the route callback(); } } }; export default (store) => { return ( <Route path="/" component={App}> <Route path="myPage" name="My Page" component={MyPage} onEnter={fetchData(store)} /> <Route path="forbitten" name="403" component={PageForbitten} /> <Route path="*" name="404" component={PageNotFound} /> </Route> ); };
Note that your router file exports thunk with your repository as an argument, if you look up, look at how we call the router, we pass it the store object.
Unfortunately, at the time of writing, the reaction router returned me 404, so I can not tell you the documents where (nextState, transition, callback) described. But, about them, from my memory:
nextState describes how the react-router route will go to:
transition function to transform, possibly another transition than one of nextState ;
callback will complete the transition on the route.
Another point to note is that with redux-thunk, your submit action can return a promise, check it in the docs here . You can find a good example here of how to configure reduct storage using decux-thunk.