-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.jsx
39 lines (37 loc) · 1.34 KB
/
routes.jsx
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
import React from 'react';
import { Router, Route, IndexRoute } from 'react-router';
import App from './containers/App';
import Editor from './containers/Editor';
import Login from './containers/login-form';
import SignupForm from './containers/signup-form';
import Password from './containers/password-form';
import ProgramLibrary from './containers/program-library';
import ProblemLibrary from './containers/problem-library';
import UserInfo from './containers/user-info';
const getRoutes = (history, store) => {
const requireAuth = (nexState, replace, callback) => {
const { user: { token } } = store.getState();
if (!token) {
replace({
pathname: '/login',
state: { nextPathname: nexState.location.pathname },
});
}
callback();
};
return (
<Router history={history}>
<Route path="/" component={App}>
<IndexRoute component={Editor} onEnter={requireAuth} />
<Route path="login" component={Login} />
<Route path="signup" component={SignupForm} />
<Route path="user">
<IndexRoute component={UserInfo} onEnter={requireAuth} />
<Route path="password" component={Password} onEnter={requireAuth} />
</Route>
<Route path="square" component={ProblemLibrary} onEnter={requireAuth} />
</Route>
</Router>
);
};
export default getRoutes;