forked from higlass/higlass-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.js
54 lines (47 loc) · 1.57 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
import PropTypes from 'prop-types';
import React from 'react';
import { Redirect, Route, Switch, withRouter } from 'react-router';
// Views
import About from '../views/About';
import Examples from '../views/Examples';
import Home from '../views/Home';
import NotFound from '../views/NotFound';
import Plugins from '../views/Plugins';
import Viewer from '../views/Viewer';
const hasDemos = typeof window.HGAC_HOMEPAGE_DEMOS !== 'undefined'
? window.HGAC_HOMEPAGE_DEMOS // from compiled `config.js`
: HGAC_HOMEPAGE_DEMOS; // from webpack's DefinePlugin
class Main extends React.Component {
componentDidUpdate(prevProps) {
if (this.props.location !== prevProps.location) {
window.scrollTo(0, 0);
}
}
render() {
return (
<Switch>
<Route exact path='/about' render={About.render} />
<Route exact path='/app' render={({ location }) => {
const query = new URLSearchParams(location.search);
const viewConfigId = query.get('config');
return <Viewer
isAuthenticated={this.props.isAuthenticated}
viewConfigId={viewConfigId} />;
}} />
<Route exact path='/examples' component={Examples} />
<Route exact path='/plugins' component={Plugins} />
{hasDemos ? (
<Route exact path='/' component={Home} />
) : (
<Redirect from="/" to="/app" />
)}
<Route component={NotFound}/>
</Switch>
);
}
}
Main.propTypes = {
isAuthenticated: PropTypes.bool,
location: PropTypes.object.isRequired,
};
export default withRouter(Main);