forked from kriasoft/react-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
47 lines (39 loc) · 1.54 KB
/
main.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
/**
* React App SDK (https://github.com/kriasoft/react-app)
*
* Copyright © 2015-present Kriasoft, LLC. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
import 'whatwg-fetch';
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import store from './core/store';
import router from './core/router';
import history from './core/history';
let routes = require('./routes.json'); // Parsed by using `utils/routes-loader.js`
const container = document.getElementById('root');
function renderComponent(component) {
ReactDOM.render(<Provider store={store}>{component}</Provider>, container);
}
// Find and render a web page matching the current URL path,
// if such page is not found then render an error page (see routes.json, core/router.js)
function render(location) {
router.resolve(routes, location)
.then(renderComponent)
.catch(error => router.resolve(routes, { ...location, error }).then(renderComponent));
}
// Handle client-side navigation by using HTML5 History API
// For more information visit https://github.com/ReactJSTraining/history/tree/master/docs#readme
history.listen(render);
render(history.getCurrentLocation());
// Enable Hot Module Replacement (HMR)
if (module.hot) {
module.hot.accept('./routes.json', () => {
// eslint-disable-next-line global-require, import/newline-after-import
routes = require('./routes.json');
render(history.getCurrentLocation());
});
}