-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathindex.js
64 lines (59 loc) · 2.17 KB
/
index.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
import React, { Suspense } from "react";
import ReactDOM from "react-dom";
import * as serviceWorker from "./serviceWorker";
import { Route, Switch } from "react-router-dom";
import { Provider } from "react-redux";
import { applyMiddleware, compose, createStore } from "redux";
import thunk from "redux-thunk";
import App from "./App";
import cloureveApp from "./reducers";
import { UpdateSiteConfig } from "./middleware/Init";
import ErrorBoundary from "./component/Placeholder/ErrorBoundary";
import { createBrowserHistory } from "history";
import { ConnectedRouter, routerMiddleware } from "connected-react-router";
import i18next from "./i18n";
import PageLoading from "./component/Placeholder/PageLoading";
import { removeI18nCache } from "./utils";
const Admin = React.lazy(() => import("./Admin"));
if (window.location.hash !== "") {
window.location.href = window.location.hash.split("#")[1];
}
serviceWorker.register({
onUpdate: (registration) => {
removeI18nCache();
alert(i18next.t("newVersionRefresh", { ns: "common" }));
if (registration && registration.waiting) {
registration.waiting.postMessage({ type: "SKIP_WAITING" });
}
window.location.reload();
},
});
export const history = createBrowserHistory();
let reduxEnhance = applyMiddleware(routerMiddleware(history), thunk);
if (
process.env.NODE_ENV === "development" &&
window.__REDUX_DEVTOOLS_EXTENSION__
) {
reduxEnhance = compose(reduxEnhance, window.__REDUX_DEVTOOLS_EXTENSION__());
}
const store = createStore(cloureveApp(history), reduxEnhance);
UpdateSiteConfig(store);
ReactDOM.render(
<Suspense fallback={<PageLoading />}>
<ErrorBoundary>
<Provider store={store}>
<ConnectedRouter history={history}>
<Switch>
<Route path="/admin">
<Admin />
</Route>
<Route exact path="">
<App />
</Route>
</Switch>
</ConnectedRouter>
</Provider>
</ErrorBoundary>
</Suspense>,
document.getElementById("root")
);