Skip to content
This repository was archived by the owner on Sep 11, 2018. It is now read-only.

Commit db66626

Browse files
(refactor)app: switch to redux-simple-router
1 parent bc477b4 commit db66626

File tree

10 files changed

+47
-30
lines changed

10 files changed

+47
-30
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Features
3434
* Includes react-addons-test-utils (`^0.14.0`)
3535
* [React-Router](https://github.com/rackt/react-router) (`^1.0.0`)
3636
* [Redux](https://github.com/gaearon/redux) (`^3.0.0`)
37-
* redux-router (`^1.0.0-beta3`)
37+
* redux-simple-router (`^0.0.10`)
3838
* react-redux (`^4.0.0`)
3939
* redux-devtools
4040
* use `npm run dev:nw` to display in a separate window.
@@ -154,7 +154,7 @@ You can redefine which packages to treat as vendor dependencies by editing `vend
154154
'react',
155155
'react-redux',
156156
'react-router',
157-
'redux-router',
157+
'redux-simple-router',
158158
'redux'
159159
]
160160
```

config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ config.set('vendor_dependencies', [
3434
'react-redux',
3535
'react-router',
3636
'redux',
37-
'redux-router'
37+
'redux-simple-router'
3838
].filter(dep => {
3939
if (pkg.dependencies[dep]) return true;
4040

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"react-redux": "^4.0.0",
3333
"react-router": "1.0.0",
3434
"redux": "^3.0.0",
35-
"redux-router": "^1.0.0-beta3",
35+
"redux-simple-router": "^0.0.10",
3636
"redux-thunk": "^1.0.0",
3737
"yargs": "^3.18.0"
3838
},

src/app.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import Root from './containers/Root';
4-
import configureStore from './store/configureStore';
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
import createBrowserHistory from 'history/lib/createBrowserHistory';
4+
import { syncReduxAndRouter } from 'redux-simple-router';
5+
import Root from './containers/Root';
6+
import configureStore from './store/configureStore';
57

6-
const target = document.getElementById('root');
7-
const store = configureStore(window.__INITIAL_STATE__, __DEBUG__);
8+
const target = document.getElementById('root');
9+
const history = createBrowserHistory();
10+
const store = configureStore(window.__INITIAL_STATE__, __DEBUG__);
11+
12+
syncReduxAndRouter(history, store);
813

914
const node = (
10-
<Root store={store}
11-
debug={__DEBUG__}
12-
debugExternal={__DEBUG_NW__} />
15+
<Root
16+
history={history}
17+
store={store}
18+
debug={__DEBUG__}
19+
debugExternal={__DEBUG_NW__}
20+
/>
1321
);
1422

1523
ReactDOM.render(node, target);

src/containers/Root.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React from 'react';
22
import { Provider } from 'react-redux';
3+
import { Router } from 'react-router';
34
import routes from '../routes';
4-
import { ReduxRouter } from 'redux-router';
55
import DevTools from './DevTools';
66
import { createDevToolsWindow } from '../utils';
77

88
export default class Root extends React.Component {
99
static propTypes = {
10-
store : React.PropTypes.object.isRequired,
11-
debug : React.PropTypes.bool,
10+
history : React.PropTypes.object.isRequired,
11+
store : React.PropTypes.object.isRequired,
12+
debug : React.PropTypes.bool,
1213
debugExternal : React.PropTypes.bool
1314
}
1415

@@ -30,9 +31,9 @@ export default class Root extends React.Component {
3031
return (
3132
<Provider store={this.props.store}>
3233
<div>
33-
<ReduxRouter>
34+
<Router history={this.props.history}>
3435
{routes}
35-
</ReduxRouter>
36+
</Router>
3637
{this.renderDevTools()}
3738
</div>
3839
</Provider>

src/reducers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { combineReducers } from 'redux';
2-
import { routerStateReducer } from 'redux-router';
2+
import { routeReducer } from 'redux-simple-router';
33
import counter from './counter';
44

55
export default combineReducers({
66
counter,
7-
router: routerStateReducer
7+
routing: routeReducer
88
});

src/routes/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import React from 'react';
22
import { Route, IndexRoute } from 'react-router';
33
import CoreLayout from 'layouts/CoreLayout';
44
import HomeView from 'views/HomeView';
5+
import AboutView from 'views/AboutView';
56

67
export default (
7-
<Route path='/' component={CoreLayout}>
8+
<Route component={CoreLayout} path='/'>
89
<IndexRoute component={HomeView} />
10+
<Route component={AboutView} path='/about' />
911
</Route>
1012
);

src/store/configureStore.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import rootReducer from '../reducers';
22
import thunk from 'redux-thunk';
3-
import routes from '../routes';
4-
import { reduxReactRouter } from 'redux-router';
5-
import createHistory from 'history/lib/createBrowserHistory';
63
import DevTools from 'containers/DevTools';
74
import {
85
applyMiddleware,
@@ -18,14 +15,8 @@ export default function configureStore (initialState, debug = false) {
1815
if (debug) {
1916
createStoreWithMiddleware = compose(
2017
middleware,
21-
reduxReactRouter({ routes, createHistory }),
2218
DevTools.instrument()
2319
);
24-
} else {
25-
createStoreWithMiddleware = compose(
26-
middleware,
27-
reduxReactRouter({ routes, createHistory })
28-
);
2920
}
3021

3122
const store = createStoreWithMiddleware(createStore)(

src/views/AboutView.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import { Link } from 'react-router';
3+
4+
const AboutView = () => (
5+
<div className='container text-center'>
6+
<h1>This is the about view!</h1>
7+
<hr />
8+
<Link to='/'>Back To Home View</Link>
9+
</div>
10+
);
11+
12+
export default AboutView;

src/views/HomeView.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { bindActionCreators } from 'redux';
33
import { connect } from 'react-redux';
44
import counterActions from 'actions/counter';
5+
import { Link } from 'react-router';
56

67
// We define mapStateToProps and mapDispatchToProps where we'd normally use
78
// the @connect decorator so the data requirements are clear upfront, but then
@@ -30,6 +31,8 @@ export class HomeView extends React.Component {
3031
onClick={this.props.actions.increment}>
3132
Increment
3233
</button>
34+
<hr />
35+
<Link to='/about'>Go To About View</Link>
3336
</div>
3437
);
3538
}

0 commit comments

Comments
 (0)