-
Notifications
You must be signed in to change notification settings - Fork 644
syncHistoryWithStore does not respect redux state #534
Comments
Debugging through if (currentLocation === locationInStore || initialLocation === locationInStore) {
return;
} in my case // Init initialLocation with potential location in store
initialLocation = getLocationInStore();
Why not to consult history for initial location? I mean, browser should know better right? When the app cold starts |
As a workaround we could simply enforce the transition to new route right after const recentLocation = (store.getState().routing || {}).locationBeforeTransitions;
const routerHistory = syncHistoryWithStore(hashHistory, store, { adjustUrlOnReplay: true });
if(recentLocation && recentLocation.pathname) {
routerHistory.replace(recentLocation.pathname);
} |
Just a random note, it seems the syncHistoryWithStore method isn't a necessity in v5.0.0 as the middleware takes care of it. So perhaps if migrating to the alpha for that, no more issues? [outside of... the alpha thing] |
It seems like react-router-redux v5.0.0 will fix a lot of things when using react-router 4. import { fromJS } from 'immutable';
import { LOCATION_CHANGE } from 'react-router-redux';
const initialState = fromJS({
locationBeforeTransitions: null
});
export default (state = initialState, action) => {
if (action.type === LOCATION_CHANGE) {
return state.set('locationBeforeTransitions', action.payload);
}
return state;
}; Or middleware will take care of it? |
@MacKentoch have you gotten a workaround for your question ☝️ |
@mentrie I ended my starter with react-router-redux 4.x.x and wrote my own reducer. I did not give a try to 5.x since I did have the use case in private or pro project then. But, I keep interesting in new about it |
Hi,
I am trying to restore the displayed page on app startup but it's always
/
, redux store is preloaded from local storage. HoweversyncHistoryWithStore
erases the state.I use
redux-localstorage
to persist redux to local storage which seems to be merging state from local storage into initialState therefore restoring the state without telling anyone which shouldn't be any different for the app when the concept of single source of truth is applied.I am sure this issue can be reproduced with
initialState
with hardcoded route.I tried
adjustUrlOnReplay
without luck:Thanks
The text was updated successfully, but these errors were encountered: