xref: /openbmc/webui-vue/src/router/index.js (revision 632de22a)
1import Vue from 'vue';
2import VueRouter from 'vue-router';
3import store from '../store/index';
4import AppLayout from '../layouts/AppLayout.vue';
5import LoginLayout from '@/layouts/LoginLayout';
6import ConsoleLayout from '@/layouts/ConsoleLayout.vue';
7
8Vue.use(VueRouter);
9
10// Meta title is translated using i18n in App.vue and PageTitle.Vue
11// Example meta: {title: 'appPageTitle.overview'}
12const routes = [
13  {
14    path: '/',
15    meta: {
16      requiresAuth: true
17    },
18    component: AppLayout,
19    children: [
20      {
21        path: '',
22        name: 'overview',
23        component: () => import('@/views/Overview'),
24        meta: {
25          title: 'appPageTitle.overview'
26        }
27      },
28      {
29        path: '/profile-settings',
30        name: 'profile-settings',
31        component: () => import('@/views/ProfileSettings'),
32        meta: {
33          title: 'appPageTitle.profileSettings'
34        }
35      },
36      {
37        path: '/health/event-logs',
38        name: 'event-logs',
39        component: () => import('@/views/Health/EventLogs'),
40        meta: {
41          title: 'appPageTitle.eventLogs'
42        }
43      },
44      {
45        path: '/health/hardware-status',
46        name: 'hardware-status',
47        component: () => import('@/views/Health/HardwareStatus'),
48        meta: {
49          title: 'appPageTitle.hardwareStatus'
50        }
51      },
52      {
53        path: '/health/sensors',
54        name: 'sensors',
55        component: () => import('@/views/Health/Sensors'),
56        meta: {
57          title: 'appPageTitle.sensors'
58        }
59      },
60      {
61        path: '/access-control/ldap',
62        name: 'ldap',
63        component: () => import('@/views/AccessControl/Ldap'),
64        meta: {
65          title: 'appPageTitle.ldap'
66        }
67      },
68      {
69        path: '/access-control/local-user-management',
70        name: 'local-users',
71        component: () => import('@/views/AccessControl/LocalUserManagement'),
72        meta: {
73          title: 'appPageTitle.localUserManagement'
74        }
75      },
76      {
77        path: '/access-control/ssl-certificates',
78        name: 'ssl-certificates',
79        component: () => import('@/views/AccessControl/SslCertificates'),
80        meta: {
81          title: 'appPageTitle.sslCertificates'
82        }
83      },
84      {
85        path: '/configuration/date-time-settings',
86        name: 'date-time-settings',
87        component: () => import('@/views/Configuration/DateTimeSettings'),
88        meta: {
89          title: 'appPageTitle.dateTimeSettings'
90        }
91      },
92      {
93        path: '/control/kvm',
94        name: 'kvm',
95        component: () => import('@/views/Control/Kvm'),
96        meta: {
97          title: 'appPageTitle.kvm'
98        }
99      },
100      {
101        path: '/control/manage-power-usage',
102        name: 'manage-power-usage',
103        component: () => import('@/views/Control/ManagePowerUsage'),
104        meta: {
105          title: 'appPageTitle.managePowerUsage'
106        }
107      },
108      {
109        path: '/configuration/network-settings',
110        name: 'network-settings',
111        component: () => import('@/views/Configuration/NetworkSettings'),
112        meta: {
113          title: 'appPageTitle.networkSettings'
114        }
115      },
116      {
117        path: '/control/reboot-bmc',
118        name: 'reboot-bmc',
119        component: () => import('@/views/Control/RebootBmc'),
120        meta: {
121          title: 'appPageTitle.rebootBmc'
122        }
123      },
124      {
125        path: '/control/server-led',
126        name: 'server-led',
127        component: () => import('@/views/Control/ServerLed'),
128        meta: {
129          title: 'appPageTitle.serverLed'
130        }
131      },
132      {
133        path: '/control/serial-over-lan',
134        name: 'serial-over-lan',
135        component: () => import('@/views/Control/SerialOverLan'),
136        meta: {
137          title: 'appPageTitle.serialOverLan'
138        }
139      },
140      {
141        path: '/control/server-power-operations',
142        name: 'server-power-operations',
143        component: () => import('@/views/Control/ServerPowerOperations'),
144        meta: {
145          title: 'appPageTitle.serverPowerOperations'
146        }
147      },
148      {
149        path: '/unauthorized',
150        name: 'unauthorized',
151        component: () => import('@/views/Unauthorized'),
152        meta: {
153          title: 'appPageTitle.unauthorized'
154        }
155      }
156    ]
157  },
158  {
159    path: '/login',
160    component: LoginLayout,
161    children: [
162      {
163        path: '',
164        name: 'login',
165        component: () => import('@/views/Login'),
166        meta: {
167          title: 'appPageTitle.login'
168        }
169      },
170      {
171        path: '/change-password',
172        name: 'change-password',
173        component: () => import('@/views/ChangePassword'),
174        meta: {
175          title: 'appPageTitle.changePassword',
176          requiresAuth: true
177        }
178      }
179    ]
180  },
181  {
182    path: '/console',
183    component: ConsoleLayout,
184    meta: {
185      requiresAuth: true
186    },
187    children: [
188      {
189        path: 'serial-over-lan-console',
190        name: 'serial-over-lan-console',
191        component: () =>
192          import('@/views/Control/SerialOverLan/SerialOverLanConsole'),
193        meta: {
194          title: 'appPageTitle.serialOverLan'
195        }
196      },
197      {
198        path: 'kvm',
199        name: 'kvm-console',
200        component: () => import('@/views/Control/Kvm/KvmConsole'),
201        meta: {
202          title: 'appPageTitle.kvm'
203        }
204      }
205    ]
206  }
207];
208
209const router = new VueRouter({
210  base: process.env.BASE_URL,
211  routes,
212  linkExactActiveClass: 'nav-link--current'
213});
214
215router.beforeEach((to, from, next) => {
216  if (to.matched.some(record => record.meta.requiresAuth)) {
217    if (store.getters['authentication/isLoggedIn']) {
218      next();
219      return;
220    }
221    next('/login');
222  } else {
223    next();
224  }
225});
226
227export default router;
228