-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathroutes.js
105 lines (98 loc) · 3.6 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React from 'react';
import {IndexRoute, Route} from 'react-router';
import {
App,
Dashboard,
ClustersPanel,
ClusterDetailsPanel,
NodesPanel,
ImagesPanel,
RegistriesPanel,
Login,
LoginSuccess,
NotFound,
ApplicationPanel,
JobsPanel,
JobDetailed,
SettingsPanel,
EventsPanel,
ContainerDetailed,
UsersPanel,
ClusterImages,
ClusterNetworks,
NetworkContainers,
AgentPanel,
ServicesPanel,
UserPassChange
} from 'containers';
export default (store) => {
const requireLogin = (nextState, replace, cb) => {
function checkNotAuth() {
const { auth: { user }} = store.getState();
if (!user) {
// oops, not logged in, so can't be here!
replace('/login');
}
cb();
}
checkNotAuth();
};
const redirectLogin = (nextState, replace, cb) => {
let redirect = '/dashboard';
if (window && window.location.search) {
let search = window.location.search.match(/\?back=(.+)/);
if (search && search[1]) {
redirect = search[1];
}
}
function checkAuth() {
const { auth: { user }} = store.getState();
if (user) {
replace(redirect);
}
cb();
}
console.log('redirect: ', redirect);
checkAuth();
};
/**
* Please keep routes in alphabetical order
*/
return (
<Route name="Home" path="/" component={App}>
<Route onEnter={requireLogin}>
{ /* Routes requiring login */ }
{ /* Home (main) route */ }
<IndexRoute name="Dashboard" component={Dashboard}/>
<Route name="Dashboard" path="dashboard" component={Dashboard}/>
<Route name="Login Successful" path="loginSuccess" component={LoginSuccess}/>
<Route name="Clusters" path="clusters" component={ClustersPanel}/>
<Route name="Containers" path="clusters/:name" component={ClusterDetailsPanel}/>
<Route name="Nodes" path="nodes" component={NodesPanel}/>
<Route name="Nodes" path="clusters/:name/nodes" component={NodesPanel}/>
<Route name="Images" path="images" component={ImagesPanel}/>
<Route name="Registries" path="registries" component={RegistriesPanel}/>
<Route name="Registries" path="clusters/:name/registries" component={RegistriesPanel}/>
<Route name="Update" path="clusters/:name/images" component={ClusterImages}/>
<Route name="Networks" path="clusters/:name/networks" component={ClusterNetworks}/>
<Route name="Network Detailed" path="clusters/:name/networks/:subname" component={NetworkContainers}/>
<Route name="Applications" path="clusters/:name/applications" component={ApplicationPanel}/>
<Route name="Jobs" path="jobs" component={JobsPanel}/>
<Route name="Settings" path="settings" component={SettingsPanel}/>
<Route name="Events" path="clusters/:name/events" component={EventsPanel}/>
<Route name="Services" path="clusters/:name/services" component={ServicesPanel}/>
<Route name="Container Detailed View" path="clusters/:name/containers/:subname" component={ContainerDetailed}/>
<Route name="Job Detailed View" path="jobs/:name" component={JobDetailed}/>
<Route name="Users" path="users" component={UsersPanel}/>
<Route name="Agent" path="agent" component={AgentPanel}/>
<Route name="My Account" path="my_account" component={UserPassChange}/>
</Route>
{ /* Public Routes */ }
<Route onEnter={redirectLogin}>
<Route name="Login" path="login" component={Login}/>
</Route>
{ /* Catch all route */ }
<Route name="Not Found" path="*" component={NotFound} status={404}/>
</Route>
);
};