-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
executable file
·35 lines (33 loc) · 1.04 KB
/
routes.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
import React from 'react'
import { Route, IndexRoute } from 'react-router'
import App from './containers/App'
import Dashboard from './containers/Dashboard'
import Users from './containers/Users'
import Categories from './containers/Categories'
import Articles from './containers/Articles'
import NotFound from './components/NotFound'
import Login from './components/Login'
import Logout from './components/Logout'
function requireAuth(nextState, replace) {
const token = localStorage.getItem('id_token')
if (!token) {
replace({
pathname: '/login',
state: {
nextPathname: nextState.location.pathname
}
})
}
}
module.exports = (
<Route path="/" component={App}>
<Route path="login" component={Login} />
<Route path="logout" component={Logout} />
<Route onEnter={requireAuth} >
<Route path="users" component={Users} />
<Route path="categories" component={Categories} />
<Route path="articles" component={Articles} />
</Route>
<Route path="*" component={NotFound} status={404} />
</Route>
)