Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit 71fd0da

Browse files
committed
async router
1 parent bc7672f commit 71fd0da

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

src/components/Router/index.jsx

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import store from 'store';
1010
import { syncHistoryWithStore } from 'react-router-redux';
1111

1212
import App from 'components/App';
13-
import Category from 'components/Category';
14-
import Categorys from 'components/Categorys';
15-
import Live from 'components/Screen';
16-
import Hot from 'components/Hot';
13+
1714
import Wiki from 'components/pageWiki';
1815
import FourOhFour from 'components/FourOhFour';
1916
import CategoryItem from 'components/CategoryItem';
@@ -26,28 +23,44 @@ const history = syncHistoryWithStore(browserHistory, store);
2623
store.dispatch(getMetadata());
2724
store.dispatch(getCategory());
2825

26+
const getAppComp = (nextState, cb) => {
27+
require.ensure([], (require) => {
28+
cb(null, require('components/App').default)
29+
}, 'app')
30+
}
31+
32+
const getCategoryComp = (nextState, cb) => {
33+
require.ensure([], (require) => {
34+
cb(null, require('components/Category').default)
35+
}, 'category')
36+
}
37+
const getCategorysComp = (nextState, cb) => {
38+
require.ensure([], (require) => {
39+
cb(null, require('components/Categorys').default)
40+
}, 'categorys')
41+
}
42+
const getLiveComp = (nextState, cb) => {
43+
require.ensure([], (require) => {
44+
cb(null, require('components/Screen').default)
45+
}, 'live')
46+
}
47+
const getHotComp = (nextState, cb) => {
48+
require.ensure([], (require) => {
49+
cb(null, require('components/Hot').default)
50+
}, 'hot')
51+
}
52+
2953
export default () => (
3054
<Provider store={store}>
3155
<Router history={history}>
3256
<Route path="/" component={App}>
33-
<IndexRoute component={Category} />
34-
<Route path="categorys" component={Category} />
35-
<Route path="categorys/:name" component={Categorys} />
36-
<Route path="hot" component={Hot} />
37-
<Route path="live" component={Live} />
57+
<IndexRoute getComponent={getCategoryComp} />
58+
<Route path="categorys" getComponent={getCategoryComp} />
59+
<Route path="categorys/:name" getComponent={getCategorysComp} />
60+
<Route path="hot" getComponent={getHotComp} />
61+
<Route path="live" getComponent={getLiveComp} />
3862
<Route path="*" component={FourOhFour} />
3963
</Route>
4064
</Router>
4165
</Provider>
4266
);
43-
44-
const checkStatus = (nextState, replace, next) => {
45-
46-
next()
47-
48-
}
49-
50-
const checkFetchStatus = (nextState, replace, next) => {
51-
if(store.getState().categorys.loading) return;
52-
next();
53-
}

0 commit comments

Comments
 (0)