Skip to content

Instantly share code, notes, and snippets.

@dawehner
Created March 26, 2018 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawehner/f57f6c4a3160deee8d6bee5390bc07ac to your computer and use it in GitHub Desktop.
Save dawehner/f57f6c4a3160deee8d6bee5390bc07ac to your computer and use it in GitHub Desktop.
diff --git a/package.json b/package.json
index 1ae5f33..cd9381a 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"react-redux": "^5.0.7",
"react-redux-loading-bar": "^3.1.2",
"react-router-dom": "^4.2.2",
+ "react-router-redux": "^4.0.8",
"redux": "^3.7.2",
"redux-devtools-extension": "^2.13.2",
"redux-saga": "^0.16.0"
diff --git a/src/App.js b/src/App.js
index 69b31f4..134122c 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,6 +1,8 @@
import React, { Component } from 'react';
-import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
-import { createStore, applyMiddleware } from 'redux';
+import { Router, Route, Switch } from 'react-router-dom';
+import createBrowserHistory from 'history/createBrowserHistory';
+import { createStore, applyMiddleware, combineReducers } from 'redux';
+import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux'
import { Provider } from 'react-redux';
import createSagaMiddleware from 'redux-saga';
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
@@ -17,21 +19,28 @@ import actions from './actions/index';
import reducers from './reducers/index';
const sagaMiddleware = createSagaMiddleware();
+
+const history = createBrowserHistory();
+
const store = createStore(
- reducers,
- {},
- composeWithDevTools(applyMiddleware(sagaMiddleware)),
+ combineReducers({
+ ...reducers,
+ router: routerReducer,
+ }),
+ composeWithDevTools(
+ applyMiddleware(sagaMiddleware, routerMiddleware(history)),
+ ),
);
sagaMiddleware.run(actions);
class App extends Component {
componentDidMount() {
- window.history.replaceState(null, null, '/');
+ history.replace('/');
}
render() {
return (
<Provider store={store}>
- <Router>
+ <ConnectedRouter history={history}>
<Default>
<Switch>
<Route exact path="/" component={Home} />
@@ -41,7 +50,7 @@ class App extends Component {
<Route component={NoMatch} />
</Switch>
</Default>
- </Router>
+ </ConnectedRouter>
</Provider>
);
}
diff --git a/yarn.lock b/yarn.lock
index 374a375..3ca38d3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5998,6 +5998,10 @@ react-router-dom@^4.2.2:
react-router "^4.2.0"
warning "^3.0.0"
+react-router-redux@^4.0.8:
+ version "4.0.8"
+ resolved "https://registry.npmjs.org/react-router-redux/-/react-router-redux-4.0.8.tgz#227403596b5151e182377dab835b5d45f0f8054e"
+
react-router@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-4.2.0.tgz#61f7b3e3770daeb24062dae3eedef1b054155986"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment