-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (62 loc) · 2.5 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//----------- Imports -----------//
import 'babel-polyfill'
import './styles/globals'
import 'file-loader?name=[name].[ext]!./static/.htaccess'
import '!file-loader?name=[name].[ext]!./static/favicon.ico'
import '!file-loader?name=[name].[ext]!./static/manifest.json'
import React from 'react'
import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'
import { LocaleProvider } from 'antd'
import { createHistory } from 'history'
import { Router,
useRouterHistory,
applyRouterMiddleware } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'
import { useScroll } from 'react-router-scroll'
import enUS from 'antd/lib/locale-provider/en_US'
import configureStore from './store'
import createRoutes from './routes'
import AppWrapper from 'containers/AppWrapper'
//----------- Definitions -----------//
const isProd = ('production' == process.env.NODE_ENV)
//----------- Redux Setups -----------//
// this uses the singleton browserHistory provided by react-router
// Optionally, this could be changed to leverage a created history
// e.g. `const browserHistory = useRouterHistory(createBrowserHistory)()`
const initialState = {}
const browserHistory = useRouterHistory(createHistory)({
basename: (isProd) ? '/nnsb-admin' : ''
})
const store = configureStore(initialState, browserHistory)
// Sync history and store, as the react-router-redux reducer
// is under the non-default key ("routing"), selectLocationState
// must be provided for resolving how to retrieve the "route" in the state
const makeSelectLocationState = () => {
return (state) => state.route
}
const history = syncHistoryWithStore(browserHistory, store, {
selectLocationState: makeSelectLocationState(),
})
//----------- Router Setups -----------//
const rootRoute = {
component : AppWrapper,
childRoutes : createRoutes(store),
}
ReactDOM.render(
<LocaleProvider locale={enUS}>
<Provider store={store}>
<Router
history={history}
routes={rootRoute}
render={applyRouterMiddleware(useScroll())}
/>
</Provider>
</LocaleProvider>,
document.getElementById('app')
)
//----------- Offline Setup -----------//
// Install ServiceWorker and AppCache in the end since
// it's not most important operation and if main code fails,
// we do not want it installed
if (isProd) require('offline-plugin/runtime').install()