xref: /openbmc/webui-vue/src/router/index.js (revision 5ea16782)
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: '/configuration/firmware',
94        name: 'firmware',
95        component: () => import('@/views/Configuration/Firmware'),
96        meta: {
97          title: 'appPageTitle.firmware'
98        }
99      },
100      {
101        path: '/control/kvm',
102        name: 'kvm',
103        component: () => import('@/views/Control/Kvm'),
104        meta: {
105          title: 'appPageTitle.kvm'
106        }
107      },
108      {
109        path: '/control/manage-power-usage',
110        name: 'manage-power-usage',
111        component: () => import('@/views/Control/ManagePowerUsage'),
112        meta: {
113          title: 'appPageTitle.managePowerUsage'
114        }
115      },
116      {
117        path: '/configuration/network-settings',
118        name: 'network-settings',
119        component: () => import('@/views/Configuration/NetworkSettings'),
120        meta: {
121          title: 'appPageTitle.networkSettings'
122        }
123      },
124      {
125        path: '/control/reboot-bmc',
126        name: 'reboot-bmc',
127        component: () => import('@/views/Control/RebootBmc'),
128        meta: {
129          title: 'appPageTitle.rebootBmc'
130        }
131      },
132      {
133        path: '/control/server-led',
134        name: 'server-led',
135        component: () => import('@/views/Control/ServerLed'),
136        meta: {
137          title: 'appPageTitle.serverLed'
138        }
139      },
140      {
141        path: '/control/serial-over-lan',
142        name: 'serial-over-lan',
143        component: () => import('@/views/Control/SerialOverLan'),
144        meta: {
145          title: 'appPageTitle.serialOverLan'
146        }
147      },
148      {
149        path: '/control/server-power-operations',
150        name: 'server-power-operations',
151        component: () => import('@/views/Control/ServerPowerOperations'),
152        meta: {
153          title: 'appPageTitle.serverPowerOperations'
154        }
155      },
156      {
157        path: '/unauthorized',
158        name: 'unauthorized',
159        component: () => import('@/views/Unauthorized'),
160        meta: {
161          title: 'appPageTitle.unauthorized'
162        }
163      }
164    ]
165  },
166  {
167    path: '/login',
168    component: LoginLayout,
169    children: [
170      {
171        path: '',
172        name: 'login',
173        component: () => import('@/views/Login'),
174        meta: {
175          title: 'appPageTitle.login'
176        }
177      },
178      {
179        path: '/change-password',
180        name: 'change-password',
181        component: () => import('@/views/ChangePassword'),
182        meta: {
183          title: 'appPageTitle.changePassword',
184          requiresAuth: true
185        }
186      }
187    ]
188  },
189  {
190    path: '/console',
191    component: ConsoleLayout,
192    meta: {
193      requiresAuth: true
194    },
195    children: [
196      {
197        path: 'serial-over-lan-console',
198        name: 'serial-over-lan-console',
199        component: () =>
200          import('@/views/Control/SerialOverLan/SerialOverLanConsole'),
201        meta: {
202          title: 'appPageTitle.serialOverLan'
203        }
204      },
205      {
206        path: 'kvm',
207        name: 'kvm-console',
208        component: () => import('@/views/Control/Kvm/KvmConsole'),
209        meta: {
210          title: 'appPageTitle.kvm'
211        }
212      }
213    ]
214  }
215];
216
217const router = new VueRouter({
218  base: process.env.BASE_URL,
219  routes,
220  linkExactActiveClass: 'nav-link--current'
221});
222
223router.beforeEach((to, from, next) => {
224  if (to.matched.some(record => record.meta.requiresAuth)) {
225    if (store.getters['authentication/isLoggedIn']) {
226      next();
227      return;
228    }
229    next('/login');
230  } else {
231    next();
232  }
233});
234
235export default router;
236