Reducers should be pure, therefore you should not try to open a new window there, instead you should create a middleware for all your fetch requests, then in a successful request you can redirect, open modals and whatever you need, for example:
import { push } from 'react-router-redux';
export default fetchMiddleware() {
return ({ dispatch, getState }) => next => action => {
if (!action.fetch) {
return next(action);
}
const promise = fetch(action.fetch, { someOptionsHere })
.then(response => response.json())
.then(data => {
if (whateverLogicYouNeedToRedirect) {
return next(push('/go/somewhere/else'));
}
next({type: action.type, response: data});
})
.catch( error => {
// check for errors in the response and
// maybe redirect to login here
next({type: 'FETCH_FAIL', error });
});
return promise;
};
}
That's a simple middleware that fetch data from your API, then parse the JSON response, then based on your logic it can redirect to a different URL or just return an action with the fetch response, you would use this middleware from your action creators like this:
export function loadData() {
return {
type: 'LOAD_SOMETHING',
fetch: '/api/something/here',
};
}
you should improve the middleware to accept params, a way to define post
, put
, delete
requests, and anything else you need, but I hope this give you an idea.