syncHistoryWithStore does not respect redux state

Author: pronebirdCreated Feb 15, 2017Updated Oct 15, 2017

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.

javascript
import { routerMiddleware, routerReducer as routing } from 'react-router-redux';
import persistState from 'redux-localstorage';
import thunk from 'redux-thunk';
import routes from './routes';

const router = routerMiddleware(hashHistory);

const reducers = {
  routing
};

const middlewares = [ thunk, router ];

function configureStore(initialState) {
  const enhancer = compose(applyMiddleware(...middlewares), persistState());
  const rootReducer = combineReducers(reducers);
  
  return createStore(rootReducer, initialState, enhancer);
}

const initialState = {};
const store = configureStore(initialState);
const routerHistory = syncHistoryWithStore(hashHistory, store);

ReactDOM.render(
  <Provider store={ store }>
    <Router history={ routerHistory } routes={ routes } />
  </Provider>,
  rootElement
);

I tried adjustUrlOnReplay without luck:

javascript
const routerHistory = syncHistoryWithStore(hashHistory, store, { adjustUrlOnReplay: true });

Thanks

Source: reactjs/react-router-redux