Skip to content

Commit 3dfecd7

Browse files
committed
feat: migrate to react-router v4
1 parent 3e07ec4 commit 3dfecd7

11 files changed

Lines changed: 48 additions & 41 deletions

File tree

.eslintrc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@
2121
"react"
2222
],
2323
"rules": {
24-
"no-console": 0,
25-
"no-plusplus": 0,
26-
"comma-dangle": 0,
2724
"arrow-parens": 0,
25+
"comma-dangle": 0,
2826
"global-require": 0,
29-
"no-param-reassign": 0,
27+
"import/no-named-as-default": 0,
3028
"max-len": ["error", 120],
29+
"no-console": 0,
30+
"no-param-reassign": 0,
31+
"no-plusplus": 0,
3132
"no-restricted-syntax": 0,
32-
"object-curly-spacing": 0,
3333
"no-underscore-dangle": 0,
34-
"import/no-named-as-default": 0,
34+
"object-curly-spacing": 0,
3535
"react/forbid-prop-types": 0,
3636
"react/jsx-filename-extension": 0,
37-
"react/prefer-stateless-function": 0 //enable
37+
"react/prefer-stateless-function": 0, //enable later
38+
"spaced-comment": 0
3839
},
3940
"settings": {
4041
"import/resolver": {

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ React boilerplate with ES2015, Express.js, and Webpack 2
44
[![Dependency Status](https://dependencyci.com/github/antonfisher/react-express-webpack2/badge)](https://dependencyci.com/github/antonfisher/react-express-webpack2)
55
[![bitHound Overall Score](https://www.bithound.io/github/antonfisher/react-express-webpack2/badges/score.svg)](https://www.bithound.io/github/antonfisher/react-express-webpack2)
66

7-
## Technologies:
7+
## Technologies
88

9-
- React
10-
- React Router
11-
- ES2015
9+
- React (v15)
10+
- React Router (v4)
11+
- ES2015+
1212
- Webpack 2 (production and development configurations)
13-
- React Hot Loader
13+
- React Hot Loader (v3-beta)
1414
- Express.js as production and development server
1515
- SCSS support (+ sanitize.css included)
1616
- React Material UI example theme
1717
- ESLint
1818

19-
## ToDo:
19+
## Features
20+
- preconfigured router
21+
- preconfigured modal windows
22+
23+
## ToDo
2024
- [ ] tests

config/webpack.config.base.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
app: './src/client/index.js',
1515
vendor: [
1616
'babel-polyfill',
17+
'history',
1718
'immutable',
1819
'material-ui',
1920
'prop-types',
@@ -22,7 +23,7 @@ module.exports = {
2223
'react-hot-loader',
2324
'react-intl',
2425
'react-redux',
25-
'react-router',
26+
'react-router-dom',
2627
'react-router-redux',
2728
'react-tap-event-plugin',
2829
'redux',

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"body-parser": "1.17.1",
4747
"compression": "1.6.2",
4848
"express": "4.15.2",
49+
"history": "4.6.1",
4950
"immutable": "3.8.1",
5051
"material-ui": "0.17.4",
5152
"prop-types": "15.5.8",
@@ -54,7 +55,7 @@
5455
"react-hot-loader": "3.0.0-beta.6",
5556
"react-intl": "2.2.3",
5657
"react-redux": "5.0.4",
57-
"react-router": "3.0.2",
58+
"react-router-dom": "4.1.1",
5859
"react-router-redux": "4.0.8",
5960
"react-tap-event-plugin": "2.0.1",
6061
"redux": "3.6.0",

src/client/components/NavigationButton/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import {Link} from 'react-router';
3+
import {NavLink} from 'react-router-dom';
44
import {lightGreen600} from 'material-ui/styles/colors';
55

66
import FlatButton from '../FlatButton';
@@ -22,11 +22,11 @@ class NavigationButton extends React.Component {
2222
const buttonStyle = {color: 'white', marginLeft: 0, marginRight: 1};
2323

2424
return (
25-
<Link to={to} onlyActiveOnIndex={to === '/'} activeStyle={activeStyle}>
25+
<NavLink to={to} activeStyle={activeStyle}>
2626
<FlatButton label={label} style={buttonStyle}>
2727
{React.Children.toArray(this.props.children)}
2828
</FlatButton>
29-
</Link>
29+
</NavLink>
3030
);
3131
}
3232
}

src/client/containers/App/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import {connect} from 'react-redux';
4+
import {Redirect, Route, Switch} from 'react-router-dom';
45
import Paper from 'material-ui/Paper';
6+
57
import AppBar from '../AppBar';
6-
import ProgressBar from '../../components/ProgressBar';
78
import AppMenu from '../AppMenu';
89
import ModalsLayout from '../ModalsLayout';
10+
import NotFound from '../NotFound';
11+
import ServersPage from '../ServersPage';
12+
import ProgressBar from '../../components/ProgressBar';
913

1014
export class App extends React.Component {
1115
static propTypes = {
12-
loading: PropTypes.bool.isRequired,
13-
children: PropTypes.node.isRequired
16+
loading: PropTypes.bool.isRequired
1417
};
1518

1619
render() {
@@ -25,7 +28,11 @@ export class App extends React.Component {
2528
{loading && <ProgressBar />}
2629
</Paper>
2730
<section style={{paddingTop: 50}}>
28-
{React.Children.toArray(this.props.children)}
31+
<Switch>
32+
<Route path="/servers" component={ServersPage} />
33+
<Route path="/users" name="home-users" component={NotFound} />
34+
<Redirect to="/servers" />
35+
</Switch>
2936
</section>
3037
<ModalsLayout />
3138
</section>

src/client/containers/AppBar/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class AppBar extends React.Component {
2020
<Toolbar>
2121
<ToolbarGroup style={{paddingLeft: 20}} firstChild>
2222
<AirplanemodeActiveIcon color="white" style={{height: 40, width: 40, marginRight: 30}} />
23-
<NavigationButton to="/" label="Servers" />
23+
<NavigationButton to="/servers" label="Servers" />
2424
<NavigationButton to="/users" label="Users" />
2525
</ToolbarGroup>
2626
<ToolbarGroup>

src/client/containers/LoginForm/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import {Link} from 'react-router';
3+
import {Link} from 'react-router-dom';
44
import Dialog from 'material-ui/Dialog';
55
import RaisedButton from 'material-ui/RaisedButton';
66

@@ -15,7 +15,7 @@ export default class LoginForm extends React.Component {
1515

1616
render() {
1717
const actions = [
18-
<Link to="/">
18+
<Link to="/servers">
1919
<RaisedButton label="Ok" secondary keyboardFocused />,
2020
</Link>
2121
];

src/client/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import React from 'react';
55
import ReactDOM from 'react-dom';
66
import {Provider} from 'react-redux';
77
import {IntlProvider} from 'react-intl';
8-
import {browserHistory} from 'react-router';
98
import {AppContainer} from 'react-hot-loader';
109
import {syncHistoryWithStore} from 'react-router-redux';
1110
import injectTapEventPlugin from 'react-tap-event-plugin';
11+
import createBrowserHistory from 'history/createBrowserHistory';
1212
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
1313

1414
// global styles
@@ -24,7 +24,7 @@ injectTapEventPlugin();
2424

2525
api.setEndpoint('/api');
2626

27-
const history = syncHistoryWithStore(browserHistory, store);
27+
const history = syncHistoryWithStore(createBrowserHistory(), store);
2828

2929
const render = (AppRouter) => {
3030
ReactDOM.render(

src/client/router.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import React from 'react';
2-
import {Router, Route, IndexRoute} from 'react-router';
2+
import {BrowserRouter, Route, Switch} from 'react-router-dom';
33

44
import App from './containers/App';
55
import LoginForm from './containers/LoginForm';
6-
import NotFound from './containers/NotFound';
7-
import ServersPage from './containers/ServersPage';
86

97
export default function ({history}) { // eslint-disable-line react/prop-types
108
return (
11-
<Router history={history}>
12-
<Route path="/" name="home" component={App}>
13-
<IndexRoute component={ServersPage} />
14-
<Route path="/users" name="home-users" component={NotFound} />
15-
</Route>
16-
<Route path="/login" name="login" component={LoginForm} />
17-
<Route path="*" name="notFound" component={NotFound} />
18-
</Router>
9+
<BrowserRouter history={history}>
10+
<Switch>
11+
<Route path="/login" name="login" component={LoginForm} />
12+
<Route path="/" name="home" component={App} />
13+
</Switch>
14+
</BrowserRouter>
1915
);
2016
}

0 commit comments

Comments
 (0)