blob: 2af53ea669048e79a8d2b97bf2bd35b701caaaf3 [file] [log] [blame]
Derick Montaguefded0d12019-12-11 06:16:40 -06001import Vue from 'vue';
2import VueRouter from 'vue-router';
3import store from '../store/index';
4import AppLayout from '../layouts/AppLayout.vue';
Derick Montaguea2988f42020-01-17 13:46:30 -06005
6Vue.use(VueRouter);
7
Dixsie Wolmerscbcd2132020-01-30 20:58:37 -06008// Meta title is translated using i18n in App.vue and PageTitle.Vue
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -08009// Example meta: {title: 'appPageTitle.overview'}
Derick Montaguea2988f42020-01-17 13:46:30 -060010const routes = [
11 {
Derick Montaguefded0d12019-12-11 06:16:40 -060012 path: '/',
13 name: '',
Derick Montaguee080a1a2019-12-04 16:30:08 -060014 meta: {
15 requiresAuth: true
16 },
17 component: AppLayout,
18 children: [
19 {
Derick Montaguefded0d12019-12-11 06:16:40 -060020 path: '',
21 component: () => import('@/views/Overview'),
Derick Montaguec8636e52019-12-06 01:28:38 -060022 meta: {
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080023 title: 'appPageTitle.overview'
Derick Montaguec8636e52019-12-06 01:28:38 -060024 }
Derick Montaguee080a1a2019-12-04 16:30:08 -060025 },
26 {
Yoshie Muranaka30abccb2020-03-11 12:44:24 -070027 path: '/health/sensors',
28 component: () => import('@/views/Health/Sensors'),
29 meta: {
30 title: 'appPageTitle.sensors'
31 }
32 },
33 {
Derick Montaguefded0d12019-12-11 06:16:40 -060034 path: '/access-control/local-user-management',
35 name: 'local-users',
36 component: () => import('@/views/AccessControl/LocalUserManagement'),
Derick Montaguec8636e52019-12-06 01:28:38 -060037 meta: {
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080038 title: 'appPageTitle.localUserManagement'
Derick Montaguec8636e52019-12-06 01:28:38 -060039 }
Derick Montague126eaab2019-12-23 13:33:52 -060040 },
41 {
Yoshie Muranaka37393812020-03-24 15:25:24 -070042 path: '/access-control/ssl-certificates',
43 name: 'ssl-certificates',
44 component: () => import('@/views/AccessControl/SslCertificates'),
45 meta: {
46 title: 'appPageTitle.sslCertificates'
47 }
48 },
49 {
Yoshie Muranakac11d3892020-02-19 08:07:40 -080050 path: '/control/reboot-bmc',
51 name: 'reboot-bmc',
52 component: () => import('@/views/Control/RebootBmc'),
53 meta: {
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080054 title: 'appPageTitle.rebootBmc'
Yoshie Muranakac11d3892020-02-19 08:07:40 -080055 }
56 },
57 {
Yoshie Muranakafa1512b2020-02-25 15:54:07 -080058 path: '/control/server-power-operations',
59 name: 'server-power-operations',
60 component: () => import('@/views/Control/ServerPowerOperations'),
61 meta: {
62 title: 'appPageTitle.serverPowerOperations'
63 }
64 },
65 {
Derick Montague126eaab2019-12-23 13:33:52 -060066 path: '/unauthorized',
67 name: 'unauthorized',
68 component: () => import('@/views/Unauthorized'),
69 meta: {
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080070 title: 'appPageTitle.unauthorized'
Derick Montague126eaab2019-12-23 13:33:52 -060071 }
Derick Montaguee080a1a2019-12-04 16:30:08 -060072 }
73 ]
Derick Montaguea2988f42020-01-17 13:46:30 -060074 },
75 {
Derick Montaguefded0d12019-12-11 06:16:40 -060076 path: '/login',
77 name: 'login',
78 component: () => import('@/views/Login'),
Derick Montaguec8636e52019-12-06 01:28:38 -060079 meta: {
Yoshie Muranaka547b5fc2020-02-24 15:42:40 -080080 title: 'appPageTitle.login'
Derick Montaguec8636e52019-12-06 01:28:38 -060081 }
Derick Montaguea2988f42020-01-17 13:46:30 -060082 }
Derick Montaguea2988f42020-01-17 13:46:30 -060083];
84
85const router = new VueRouter({
Derick Montaguea2988f42020-01-17 13:46:30 -060086 base: process.env.BASE_URL,
87 routes,
Yoshie Muranaka71ac2302019-12-26 11:43:36 -080088 linkExactActiveClass: 'nav-link--current'
Derick Montaguea2988f42020-01-17 13:46:30 -060089});
90
Derick Montaguee080a1a2019-12-04 16:30:08 -060091router.beforeEach((to, from, next) => {
92 if (to.matched.some(record => record.meta.requiresAuth)) {
Derick Montaguefded0d12019-12-11 06:16:40 -060093 if (store.getters['authentication/isLoggedIn']) {
Derick Montaguee080a1a2019-12-04 16:30:08 -060094 next();
95 return;
96 }
Derick Montaguefded0d12019-12-11 06:16:40 -060097 next('/login');
Derick Montaguee080a1a2019-12-04 16:30:08 -060098 } else {
99 next();
100 }
101});
102
Derick Montaguea2988f42020-01-17 13:46:30 -0600103export default router;