Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to react-router-v4 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chapter-11/react_router_basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
"react-scripts": "0.8.4"
},
"dependencies": {
"history": "^4.6.2",
"react": "^15.4.1",
"react-dom": "^15.4.1",
"react-redux": "^5.0.1",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.7",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1",
"react-router-redux": "^5.0.0-alpha.6",
"redux": "^3.6.0"
},
"scripts": {
Expand Down
41 changes: 20 additions & 21 deletions chapter-11/react_router_basic/src/Routes.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import React from 'react';
import {Router, Route, IndexRoute, browserHistory} from 'react-router';
import {Route, Switch} from 'react-router-dom';
import {Provider} from 'react-redux';

import {syncHistoryWithStore} from 'react-router-redux';
//import {syncHistoryWithStore} from 'react-router-redux';
import {ConnectedRouter} from 'react-router-redux';
import createBrowserHistory from 'history/createBrowserHistory';

import App from './pages/App.js';
import {view as TopMenu} from './components/TopMenu';

//import App from './pages/App.js';
import Home from './pages/Home.js';
import About from './pages/About.js';
import NotFound from './pages/NotFound.js';
import store from './Store.js';

const createElement = (Component, props) => {
return (
<Provider store={store}>
<Component {...props} />
</Provider>
);
};

const history = syncHistoryWithStore(browserHistory, store);
//const history = browserHistory;
const history = createBrowserHistory();

const Routes = () => (
<Router history={history} createElement={createElement}>
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Route path="home" component={Home} />
<Route path="about" component={About} />
<Route path="*" component={NotFound} />
</Route>
</Router>
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
<TopMenu />
<Switch>
<Route exact path="/" component={Home} />
<Route exact path="/about" component={About} />
<Route path="*" component={NotFound} />
</Switch>
</div>
</ConnectedRouter>
</Provider>
);

export default Routes;
4 changes: 2 additions & 2 deletions chapter-11/react_router_basic/src/components/TopMenu/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {Link} from 'react-router';
import {Link} from 'react-router-dom';

const liStyle = {
display: 'inline-block',
Expand All @@ -11,7 +11,7 @@ const view = () => {
return (
<div>
<ul>
<li style={liStyle}><Link to="/home">Home</Link></li>
<li style={liStyle}><Link to="/">Home</Link></li>
<li style={liStyle}><Link to="/about">About</Link></li>
</ul>
</div>
Expand Down