Repository navigation
Expand file tree
/
Copy pathclient.js
More file actions
executable file
·80 lines (69 loc) · 2.03 KB
/
Copy pathclient.js
File metadata and controls
executable file
·80 lines (69 loc) · 2.03 KB
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
/**
* THIS IS THE ENTRY POINT FOR THE CLIENT, JUST LIKE server.js IS THE ENTRY POINT FOR THE SERVER.
*/
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import { useBasename } from 'history';
import getRoutes from './routes';
import globals from './Globals';
import { store } from './store';
const hashLinkScroll = () => {
const { hash } = window.location;
if (hash !== '') {
// Push onto callback queue so it runs after the DOM is updated,
// this is required when navigating from a different page so that
// the element is rendered on the page before trying to getElementById.
setTimeout(() => {
const id = hash.replace('#', '');
const element = document.getElementById(id);
if (element) {
element.scrollIntoView();
}
}, 0);
} else {
// This is a hack to solve the issue with scroll retention during page change.
setTimeout(() => {
const element = document.getElementsByTagName('body');
if (element && element.length > 0) {
element[0].scrollIntoView();
}
}, 0);
}
};
const history = syncHistoryWithStore(browserHistory, store);
/* ****************************************************************** */
// Enable hot reloading
if (__DEVELOPMENT__ && module.hot) {
/*
module.hot.accept('./reducer', () => {
store.replaceReducer(require('./reducer'));
});
*/
module.hot.accept();
}
// Main routes and rendering
const Main = () => {
const routeHistory = useBasename(() => history)({
basename: globals.urlPrefix,
});
return (
<Router
history={routeHistory}
routes={getRoutes(store)}
onUpdate={hashLinkScroll}
/>
);
};
const dest = document.getElementById('content');
ReactDOM.render(
<Provider store={store} key="provider">
<Main />
</Provider>,
dest
);
if (process.env.NODE_ENV !== 'production') {
window.React = React; // enable debugger
}