-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (38 loc) · 1.32 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
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import AppRoot from './AppRoot';
import { setServerSideRenderingState } from './RouteHandler';
import i18ninit from './i18n';
/* eslint-disable no-underscore-dangle */
let renderFunction = ReactDOM.render;
/*
SSR Data
If we're running in a server-side rendering scenario,
the server will provide the window.__JSS_STATE__ object
for us to acquire the initial state to run with on the client.
This enables us to skip a network request to load up the layout data.
SSR is initiated from /server/server.js.
*/
if (window.__JSS_STATE__) {
// push the initial SSR state into the route handler, where it will be used
setServerSideRenderingState(window.__JSS_STATE__);
// when React initializes from a SSR-based initial state, you need to render with `hydrate` instead of `render`
renderFunction = ReactDOM.hydrate;
}
/*
App Rendering
*/
// initialize the dictionary, then render the app
// note: if not making a multlingual app, the dictionary init can be removed.
i18ninit().then(() => {
// HTML element to place the app into
const rootElement = document.getElementById('root');
renderFunction(
<AppRoot
path={window.location.pathname}
Router={BrowserRouter}
/>,
rootElement
);
});