When is LOCATION_CHANGE detected in the middleware?
joetidee opened this issue · 0 comments
joetidee commented
We are looking at intercepting the LOCATION_CHANGE action in middleware to decide whether to redirect or not:
import { LOCATION_CHANGE } from 'react-router-redux';
import { getBasePath } from 'src/services/metadata/reducer';
const performHardReload = ({ action }) =>
action.type === LOCATION_CHANGE &&
action.payload &&
action.payload.pathname === '/home';
const middleware = ({ getState }) => next => {
return action => {
if (performHardReload({ action })) {
const redirectUrl = '/somewhere-else';
window.location.replace(redirectUrl);
return Promise.resolve();
}
return next(action);
};
};
export default middleware;
We were wondering if the LOCATION_CHANGE action is guaranteed to be detected before the home page starts to render and will, therefore, avoid a flash of content before the redirect kicks in. It would be really good to have a diagram to understand the flow.