Skip to content

Commit d25b66d

Browse files
committed
update code to work with react-redux-router 4.0.0
1 parent 5fb1c8b commit d25b66d

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

client/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Router } from 'react-router';
66
import { routes } from '../common/routes';
77
import configureStore from '../common/config/store';
88
import { browserHistory, hashHistory } from 'react-router';
9+
import { syncHistoryWithStore } from 'react-router-redux';
910

1011
/* Images
1112
* This space is reserved for images that are required by server rendering,
@@ -25,9 +26,12 @@ const rootElement = document.getElementById('app');
2526

2627
// Creates the Redux store based on the initial state passed down by the server
2728
// rendering.
28-
const history = __CORDOVA__ ? hashHistory : browserHistory;
29+
const store = configureStore(initialState);
30+
const history = syncHistoryWithStore(
31+
(__CORDOVA__ ? hashHistory : browserHistory),
32+
store
33+
);
2934
const initialState = window.__INITIAL_STATE__;
30-
const store = configureStore(initialState, history);
3135

3236
/* FastClick
3337
* Disables the 300ms delay for mobile apps. Comment out or add a conditional

common/config/store.dev.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { compose, createStore, applyMiddleware } from 'redux';
22
import thunk from 'redux-thunk';
33
import rootReducer from '../reducers';
44
import persistState from 'redux-localstorage';
5-
import { syncHistory } from 'react-router-redux';
65
import DevTools from '../shared/containers/DevTools';
76

87
/* localStorage Persisted States
@@ -12,7 +11,7 @@ import DevTools from '../shared/containers/DevTools';
1211
*/
1312
const persistedStates = [];
1413

15-
export default function configureStore(initialState, history = null) {
14+
export default function configureStore(initialState, localStorage = true) {
1615
/* Middleware
1716
* Configure this array with the middleware that you want included. thunk
1817
* is included by default, and react-router-redux's syncHistory is also
@@ -27,9 +26,8 @@ export default function configureStore(initialState, history = null) {
2726

2827
// Client-side enhancers and middleware
2928
if (isBrowser()) {
30-
enhancers.push(persistState(persistedStates));
31-
if (history) {
32-
middleware.push(syncHistory(history));
29+
if (localStorage) {
30+
enhancers.push(persistState(persistedStates));
3331
}
3432
}
3533

common/config/store.prod.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { compose, createStore, applyMiddleware } from 'redux';
22
import thunk from 'redux-thunk';
33
import rootReducer from '../reducers';
44
import persistState from 'redux-localstorage';
5-
import { syncHistory } from 'react-router-redux';
65

76
/* localStorage Persisted States
87
* Set up persisted state properties via localStorage. They should be added
@@ -11,7 +10,7 @@ import { syncHistory } from 'react-router-redux';
1110
*/
1211
const persistedStates = [];
1312

14-
export default function configureStore(initialState, history = null) {
13+
export default function configureStore(initialState, localStorage = true) {
1514
/* Middleware
1615
* Configure this array with the middleware that you want included. thunk
1716
* is included by default, and react-router-redux's syncHistory is also
@@ -20,13 +19,12 @@ export default function configureStore(initialState, history = null) {
2019
let middleware = [thunk];
2120

2221
// Add universal enhancers here
23-
let enhancers = [];
22+
let enhancers = [];
2423

2524
// Client-side enhancers and middleware
2625
if (isBrowser()) {
27-
enhancers.push(persistState(persistedStates));
28-
if (history) {
29-
middleware.push(syncHistory(history));
26+
if (localStorage) {
27+
enhancers.push(persistState(persistedStates));
3028
}
3129
}
3230

common/reducers/example.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const example = (state = defaultState, action) => {
88
default:
99
return state;
1010
}
11-
12-
return state;
1311
};
1412

1513
export default example;

common/reducers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { combineReducers } from 'redux';
2-
import { routeReducer } from 'react-router-redux';
2+
import { routerReducer } from 'react-router-redux';
33

44
// Import your reducers here
55
import example from './example';
66

77
const rootReducer = combineReducers({
8-
routing: routeReducer,
8+
routing: routerReducer,
99
example
1010
});
1111

0 commit comments

Comments
 (0)