-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (38 loc) · 1.45 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
import React from 'react';
import Store from 'redux/store';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Router, Route, IndexRoute, browserHistory } from 'react-router';
import PageContainer from 'containers/PageContainer';
import NotFoundPage from 'containers/NotFoundPage';
import AuthPage from 'containers/AuthPage';
import HomePage from 'containers/HomePage';
import { loginSuccess } from 'redux/modules/user';
import { levels } from 'utils/access';
import Token from 'utils/token';
const store = Store();
// @todo: Abstract persistent login into HOC.
// Should verify token on refresh by hitting API.
const token = Token.get();
if(token) store.dispatch(loginSuccess(token));
const routesUsingDifferentTag = (
<Provider store={store}>
<Router history={browserHistory}>
<Route path="/">
{/* Routes that require a logged in user */}
<Route component={PageContainer(levels.USER)}>
<IndexRoute component={HomePage}/>
</Route>
{/* Routes that require a guest user */}
<Route component={PageContainer(levels.GUEST)}>
<Route path="/auth" component={AuthPage}/>
</Route>
{/* Routes that are available to all */}
<Route component={PageContainer(levels.ALL)}>
<Route path="/*" component={NotFoundPage}/>
</Route>
</Route>
</Router>
</Provider>
);
render(routesUsingDifferentTag, document.getElementById('root'));