-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.jsx
60 lines (52 loc) · 1.67 KB
/
client.jsx
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
import "babel-polyfill"
import React from "react"
import ReactDOM from "react-dom"
import * as ReactRedux from "react-redux"
import * as ReduxRouter from "react-router-redux"
import Routes from "./core/Routes"
import Store from "./core/Store"
import History from "./core/History"
const FastClick = require("fastclick")
import "modernizr" // to set classes on 'html' tag
import "./content/index.less"
const store = Store(window.__INITIAL_STATE__)
const render = () => {
let routes = <Routes />
if (__DEVELOPMENT__) {
const AppContainer = require("react-hot-loader").AppContainer
routes = React.createElement(AppContainer, {}, routes)
}
ReactDOM.render(
<ReactRedux.Provider store={store}>
<ReduxRouter.ConnectedRouter history={History}>
{routes}
</ReduxRouter.ConnectedRouter>
</ReactRedux.Provider>,
document.getElementById("root")
)
}
render()
if (__DEVELOPMENT__) {
// remove server css bundle to not interfere with styles applied by webpack's style-loader
const cssBundleElem = document.getElementById("css-bundle-main")
if (cssBundleElem)
cssBundleElem.parentNode.removeChild(cssBundleElem)
if (module.hot)
module.hot.accept("./core/Routes", render)
}
// remove empty hash from url
function handleEmptyHash() {
if (window.history.replaceState)
setTimeout(() => {
const re = /#\/*$/
const url = String(window.location)
if (re.test(url))
window.history.replaceState(null, null, url.replace(re, ""))
}, 100)
}
handleEmptyHash()
History.listen(handleEmptyHash)
if ("addEventListener" in document)
document.addEventListener("DOMContentLoaded", () => {
FastClick.attach(document.body)
}, false)