xref: /openbmc/webui-vue/src/router/index.js (revision 30abccbe)
1import Vue from 'vue';
2import VueRouter from 'vue-router';
3import store from '../store/index';
4import AppLayout from '../layouts/AppLayout.vue';
5
6Vue.use(VueRouter);
7
8// Meta title is translated using i18n in App.vue and PageTitle.Vue
9// Example meta: {title: 'appPageTitle.overview'}
10const routes = [
11  {
12    path: '/',
13    name: '',
14    meta: {
15      requiresAuth: true
16    },
17    component: AppLayout,
18    children: [
19      {
20        path: '',
21        component: () => import('@/views/Overview'),
22        meta: {
23          title: 'appPageTitle.overview'
24        }
25      },
26      {
27        path: '/health/sensors',
28        component: () => import('@/views/Health/Sensors'),
29        meta: {
30          title: 'appPageTitle.sensors'
31        }
32      },
33      {
34        path: '/access-control/local-user-management',
35        name: 'local-users',
36        component: () => import('@/views/AccessControl/LocalUserManagement'),
37        meta: {
38          title: 'appPageTitle.localUserManagement'
39        }
40      },
41      {
42        path: '/control/reboot-bmc',
43        name: 'reboot-bmc',
44        component: () => import('@/views/Control/RebootBmc'),
45        meta: {
46          title: 'appPageTitle.rebootBmc'
47        }
48      },
49      {
50        path: '/control/server-power-operations',
51        name: 'server-power-operations',
52        component: () => import('@/views/Control/ServerPowerOperations'),
53        meta: {
54          title: 'appPageTitle.serverPowerOperations'
55        }
56      },
57      {
58        path: '/unauthorized',
59        name: 'unauthorized',
60        component: () => import('@/views/Unauthorized'),
61        meta: {
62          title: 'appPageTitle.unauthorized'
63        }
64      }
65    ]
66  },
67  {
68    path: '/login',
69    name: 'login',
70    component: () => import('@/views/Login'),
71    meta: {
72      title: 'appPageTitle.login'
73    }
74  }
75];
76
77const router = new VueRouter({
78  base: process.env.BASE_URL,
79  routes,
80  linkExactActiveClass: 'nav-link--current'
81});
82
83router.beforeEach((to, from, next) => {
84  if (to.matched.some(record => record.meta.requiresAuth)) {
85    if (store.getters['authentication/isLoggedIn']) {
86      next();
87      return;
88    }
89    next('/login');
90  } else {
91    next();
92  }
93});
94
95export default router;
96