Skip to content

Commit 18dabb5

Browse files
author
Sven
committed
优化结构
1 parent 26de39f commit 18dabb5

File tree

24 files changed

+456
-177
lines changed

24 files changed

+456
-177
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ cache:
77
yarn: true
88
directories:
99
- node_modules
10+
before_install:
11+
# CI server install taobao npm packages too slow.
12+
- rm -rf ./yarn.lock
1013

1114
script:
1215
- yarn lint

build/scripts/start.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const logger = require('../lib/logger')
2+
const openBrowser = require('react-dev-utils/openBrowser')
23

34
logger.info('Starting server...')
45
require('../../server/main').listen(3000, () => {
56
logger.success('==> 🌎 Server is running at http://localhost:3000')
7+
openBrowser('http://localhost:3000')
68
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"html-webpack-plugin": "^2.24.1",
7575
"http-proxy-middleware": "^0.17.4",
7676
"node-sass": "^4.5.3",
77+
"react-dev-utils": "^4.1.0",
7778
"rimraf": "^2.6.1",
7879
"sass-loader": "^6.0.5",
7980
"source-map-explorer": "^1.5.0",

project.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ module.exports = {
1818
/** Whether to generate sourcemaps */
1919
sourcemaps: GENERATE_SOURCEMAP,
2020
/** A hash map of keys that the compiler should treat as external to the project */
21-
externals: {},
21+
externals: {
22+
react: 'React',
23+
'react-dom': 'ReactDOM',
24+
},
2225
/** A hash map of variables and their values to expose globally */
2326
globals: {},
2427
/** Whether to enable verbose logging */
2528
verbose: false,
2629
/** The list of modules to bundle separately from the core application code */
2730
vendors: [
2831
'axios',
29-
'react',
30-
'react-dom',
3132
'redux',
3233
'react-redux',
34+
'reactstrap',
3335
'redux-thunk',
3436
'react-router-dom',
35-
'reactstrap',
3637
'react-spinkit',
3738
'prop-types',
3839
'immutability-helper-x',

src/components/App.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react'
2-
import { Router } from 'react-router-dom'
2+
import { Router, Route } from 'react-router-dom'
33
import { Provider } from 'react-redux'
44
import { object } from 'prop-types'
55
import Layout from '../layouts'
@@ -19,11 +19,9 @@ class App extends Component {
1919

2020
return (
2121
<Provider store={store}>
22-
<div style={{ height: '100%' }}>
23-
<Router history={history}>
24-
<Layout />
25-
</Router>
26-
</div>
22+
<Router history={history}>
23+
<Route component={Layout} />
24+
</Router>
2725
</Provider>
2826
)
2927
}

src/components/PrivateRoute.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33
import { Route, Redirect } from 'react-router-dom'
4-
import { connect } from 'react-redux'
54

65
const propTypes = {
76
isAuthenticated: PropTypes.bool.isRequired,
87
component: PropTypes.func.isRequired,
9-
location: PropTypes.object.isRequired,
108
}
119

1210
function PrivateRoute({ component: Component, isAuthenticated, ...rest }) {
1311
return (
14-
<Route {...rest} render={props => (
15-
isAuthenticated ? (
16-
<Component {...props} />
17-
) : (
18-
<Redirect to={{
12+
<Route {...rest} render={_props => (
13+
isAuthenticated
14+
? <Component {..._props} />
15+
: <Redirect to={{
1916
pathname: '/login',
20-
state: { from: props.location }
17+
state: { from: _props.location }
2118
}}
2219
/>
23-
)
2420
)}
2521
/>
26-
2722
)
2823
}
2924

3025
PrivateRoute.propTypes = propTypes
3126

32-
const mapStateToProps = (state) => ({
33-
isAuthenticated: state.isAuthenticated
34-
})
35-
36-
export default connect(mapStateToProps)(PrivateRoute)
27+
export default PrivateRoute

src/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
</head>
88
<body>
99
<div id="root" style="height: 100%"></div>
10+
<script src="https://cdn.bootcss.com/react/16.0.0/umd/react.production.min.js"></script>
11+
<script src="https://cdn.bootcss.com/react-dom/16.0.0/umd/react-dom.production.min.js"></script>
1012
</body>
1113
</html>

src/layouts/components/CustomHome.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/layouts/components/Layout.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/layouts/components/Navbar.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import React, { Component } from 'react'
22
import { func } from 'prop-types'
33
import { Collapse, Navbar, NavbarToggler, NavbarBrand, Nav, NavLink } from 'reactstrap'
44
import { NavLink as Link } from 'react-router-dom'
5-
import { AsyncZen } from './CustomHome'
65

7-
export default class CustomNavbar extends Component {
6+
import { AsyncZen } from '../../routes'
7+
8+
class CustomNavbar extends Component {
89
static propTypes = {
910
signOut: func.isRequired,
1011
}
@@ -19,11 +20,6 @@ export default class CustomNavbar extends Component {
1920
})
2021
}
2122

22-
signOut = () => {
23-
this.props.signOut()
24-
localStorage.setItem('LoginState', 'false')
25-
}
26-
2723
onMouseOver = () => {
2824
AsyncZen.preload()
2925
}
@@ -36,11 +32,13 @@ export default class CustomNavbar extends Component {
3632
<Collapse isOpen={this.state.isOpen} navbar>
3733
<Nav className="ml-auto" navbar>
3834
<NavLink to="/zenPage" onMouseOver={this.onMouseOver} tag={Link}>Zen</NavLink>
39-
<NavLink href="javascript:;" onClick={this.signOut}>Sign out</NavLink>
35+
<NavLink href="javascript:;" onClick={this.props.signOut}>Sign out</NavLink>
4036
<NavLink href="https://github.com/YutHelloWorld/vortex-react">Github</NavLink>
4137
</Nav>
4238
</Collapse>
4339
</Navbar>
4440
)
4541
}
4642
}
43+
44+
export default CustomNavbar

0 commit comments

Comments
 (0)