/
main.js
55 lines (45 loc) · 1.43 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
48
49
50
51
52
53
54
55
import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { Provider } from 'react-redux';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import store from './store';
import WrappedViewport from './components/WrappedViewport';
// Detect users incorrectly hitting /locations/username instead of /username.
// It seems people think because the plugin is POSTing -> /location/username that they must
// view in browser at same url. This is incorrect.
const path = window.location.pathname;
const pathQuery = path.match(/^\/locations\/(.*)$/);
if (pathQuery) {
// Redirect /locations/username -> /username
window.location.pathname = pathQuery[1];
}
const locationHash = (location.hash || '').substring(1);
if (locationHash) {
window.location = '/' + locationHash;
}
const container = document.querySelector('#app-container');
const render = () => {
ReactDOM.render(
<AppContainer>
<Provider store={store}>
<Router>
<Switch>
<Route path='/:token' component={WrappedViewport} />
<Route path='/' component={WrappedViewport} />
</Switch>
</Router>
</Provider>
</AppContainer>,
container
);
};
render();
if (module.hot) {
module.hot.accept('./components/Viewport', () => {
setImmediate(() => {
ReactDOM.unmountComponentAtNode(container);
render();
});
});
}