Skip to content

Commit 34b2c8a

Browse files
committed
feat(*) upgrade [email protected] & react-router-redux
* Upgraded to latest version of react-router - fix #14 * Switched from redux-router to react-router-redux - fix #13 * This upgrade fixes #12 (problem when reloading a lazyly loaded route)
1 parent cc80eb5 commit 34b2c8a

File tree

5 files changed

+28
-34
lines changed

5 files changed

+28
-34
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,16 @@
9696
"dependencies": {
9797
"bootstrap-sass": "^3.3.5",
9898
"es6-promise": "^3.0.2",
99-
"history": "^1.17.0",
10099
"lscache": "^1.0.5",
101100
"react": "^0.14.7",
102101
"react-dom": "^0.14.7",
103102
"react-redux": "~4.1.2",
104-
"react-router": "^1.0.3",
103+
"react-router": "^2.0.0",
104+
"react-router-redux": "^3.0.0",
105105
"redux": "~3.1.7",
106106
"redux-devtools": "~3.0.2",
107107
"redux-devtools-dock-monitor": "^1.0.1",
108108
"redux-devtools-log-monitor": "^1.0.1",
109-
"redux-router": "^1.0.0-beta7",
110109
"superagent": "^1.7.2",
111110
"superagent-mocker": "^0.3.0"
112111
},

src/bootstrap.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ global.Promise = global.Promise || require('es6-promise').Promise;
33
import React from 'react';
44
import ReactDOM from 'react-dom';
55

6-
import { ReduxRouter } from 'redux-router';
6+
import { Router, hashHistory } from 'react-router';
77
import { Provider } from 'react-redux';
88

99
import routes from './routes.js';
@@ -14,12 +14,16 @@ import configureStore from './redux/configure-store.js';
1414
import httpService from './services/httpService.js';
1515
httpService.getInstance();
1616

17-
/** Redux initialization */
17+
/**
18+
* Router initialization
19+
* react-router-redux config is done in configure-store
20+
* If you switch from hashHistory to another, please update configure-store.js
21+
*/
1822

1923
const component = (
20-
<ReduxRouter>
24+
<Router history={hashHistory}>
2125
{routes}
22-
</ReduxRouter>
26+
</Router>
2327
);
2428

2529
const initialState = {};

src/containers/App/App.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const App = ({ children }) => {
1818
};
1919

2020
App.propTypes = {
21-
routerState: React.PropTypes.object.isRequired,
21+
routing: React.PropTypes.object.isRequired,
2222
children: React.PropTypes.node.isRequired
2323
};
2424

25-
export default connect(state => ({ routerState: state.router }))(App);
25+
export default connect(state => ({ routing: state.routing }))(App);

src/redux/configure-store.js

+14-23
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,22 @@
44
* I added some comments to help understand the code
55
*/
66

7+
import { hashHistory } from 'react-router';// using the same as the one in bootstrap.js @todo find a way to inject it ?
78
import { createStore, compose, applyMiddleware } from 'redux';
8-
import { reduxReactRouter } from 'redux-router';
9-
import createHashHistory from 'history/lib/createHashHistory';
10-
import clientMiddleware from './middleware/clientMiddleware';
9+
import { syncHistory } from 'react-router-redux';
1110

12-
const createHistory = () => {
13-
return createHashHistory({queryKey: 'hash'});
14-
};
11+
import clientMiddleware from './middleware/clientMiddleware';
1512

16-
let combinedCreateStore;
13+
/**
14+
* react-redux-router middleware setup
15+
*/
16+
const reduxRouterMiddleware = syncHistory(hashHistory);
1717

1818
/**
1919
* https://github.com/rackt/redux/blob/master/docs/Glossary.md#store-enhancer
2020
* Higher order function that compose a store creator and returns a new one: (StoreCreator) => (StoreCreator)
2121
*/
22-
const storeEnhancers = [
23-
reduxReactRouter({
24-
createHistory,
25-
routerStateSelector: state => ({
26-
location: {
27-
pathname: undefined
28-
},
29-
routes: [],
30-
params: {},
31-
components: [],
32-
...state.router
33-
})
34-
})
35-
];
22+
const storeEnhancers = [];
3623

3724
/**
3825
* Only require then add devtools to the store-enhancer when needed
@@ -46,9 +33,9 @@ if (process.env.DEVTOOLS) {
4633
* Compose the store-enhancers with the original createStore function to create a new composed one.
4734
* Same as: combinedCreateStore = storeEnhancers[0](storeEnhancers[1](createStore))
4835
*/
49-
combinedCreateStore = compose(...storeEnhancers)(createStore);
36+
const combinedCreateStore = compose(...storeEnhancers)(createStore);
5037

51-
const middlewares = [clientMiddleware];
38+
const middlewares = [clientMiddleware, reduxRouterMiddleware];
5239

5340
if (process.env.DEVTOOLS) {
5441
middlewares.push(require('./middleware/logger'));
@@ -77,6 +64,10 @@ export default function configureStore(initialState) {
7764
*/
7865
const store = finalCreateStore(rootReducer, initialState);
7966

67+
if (process.env.DEVTOOLS) {
68+
reduxRouterMiddleware.listenForReplays(store);
69+
}
70+
8071
if (module.hot) {
8172
// Enable Webpack hot module replacement for reducers
8273
module.hot.accept('./modules/reducer', () => {

src/redux/modules/reducer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { combineReducers } from 'redux';
2-
import { routerStateReducer } from 'redux-router';
2+
import { routeReducer } from 'react-router-redux';// the middleware part configuration of react-redux-router is done in configure-store.js
33

44
// reducers specific to app logic - to see an annotated reducer, open src/redux/modules/multipleUsers.js
55
import counter from './counter.js';
@@ -11,7 +11,7 @@ import singleUser from './singleUser.js';
1111
* (including the reducer of the router, since we use redux-router and so the state of the router is in the store)
1212
*/
1313
export default combineReducers({
14-
router: routerStateReducer,
14+
routing: routeReducer,
1515
counter,
1616
multipleUsers,
1717
singleUser

0 commit comments

Comments
 (0)