@@ -2,6 +2,7 @@ import React, { Component } from 'react'
22import ReactDOM from 'react-dom'
33import { BrowserRouter , HashRouter , Route , Switch } from 'react-router-dom'
44import { createStore , applyMiddleware , compose } from 'redux'
5+ import Loadable from 'react-loadable'
56import thunk from 'redux-thunk'
67import { Provider } from 'react-redux'
78import { reducer } from './redux/store'
@@ -14,10 +15,31 @@ import 'animate.css/animate.min.css'
1415import PageLoading from '@components/PageLoading'
1516
1617// 页面
17- import Index from './Pages/Index'
18+ // import Index from './Pages/Index'
1819import Article from './Pages/Articles'
19- import Archives from './Pages/Archives'
20- import Friend from './Pages/Friend'
20+ // import Archives from './Pages/Archives'
21+ // import Friend from './Pages/Friend'
22+ // 动态路由加载,提升用户感受
23+ const AsyncIndex = Loadable ( {
24+ loading : PageLoading ,
25+ timeout : 1000 ,
26+ loader : ( ) => import ( './Pages/Index' )
27+ } )
28+ // const AsyncArticle = Loadable({
29+ // loading: PageLoading ,
30+ // timeout: 1000,
31+ // loader: () => import('./Pages/Articles')
32+ // })
33+ const AsyncArchives = Loadable ( {
34+ loading : PageLoading ,
35+ timeout : 1000 ,
36+ loader : ( ) => import ( './Pages/Archives' )
37+ } )
38+ const AsyncFriend = Loadable ( {
39+ loading : PageLoading ,
40+ timeout : 1000 ,
41+ loader : ( ) => import ( './Pages/Friend' )
42+ } )
2143
2244const store = createStore ( reducer , compose (
2345 applyMiddleware ( thunk ) ,
@@ -32,10 +54,10 @@ class App extends Component {
3254 < BrowserRouter >
3355 { /* <HashRouter> */ }
3456 < Switch >
35- < Route path = '/' exact component = { Index } />
57+ < Route path = '/' exact component = { AsyncIndex } />
3658 < Route path = '/articles/:id' component = { Article } />
37- < Route path = '/archives' component = { Archives } />
38- < Route path = '/friend' component = { Friend } />
59+ < Route path = '/archives' component = { AsyncArchives } />
60+ < Route path = '/friend' component = { AsyncFriend } />
3961 </ Switch >
4062 { /* </HashRouter> */ }
4163 </ BrowserRouter >
0 commit comments