xref: /openbmc/webui-vue/src/router/index.js (revision 6859203cebe3b6a31d23d55a3555bf36d6c73242)
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: '/access-control/ssl-certificates',
43        name: 'ssl-certificates',
44        component: () => import('@/views/AccessControl/SslCertificates'),
45        meta: {
46          title: 'appPageTitle.sslCertificates'
47        }
48      },
49      {
50        path: '/control/reboot-bmc',
51        name: 'reboot-bmc',
52        component: () => import('@/views/Control/RebootBmc'),
53        meta: {
54          title: 'appPageTitle.rebootBmc'
55        }
56      },
57      {
58        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      {
66        path: '/unauthorized',
67        name: 'unauthorized',
68        component: () => import('@/views/Unauthorized'),
69        meta: {
70          title: 'appPageTitle.unauthorized'
71        }
72      }
73    ]
74  },
75  {
76    path: '/login',
77    name: 'login',
78    component: () => import('@/views/Login'),
79    meta: {
80      title: 'appPageTitle.login'
81    }
82  }
83];
84
85const router = new VueRouter({
86  base: process.env.BASE_URL,
87  routes,
88  linkExactActiveClass: 'nav-link--current'
89});
90
91router.beforeEach((to, from, next) => {
92  if (to.matched.some(record => record.meta.requiresAuth)) {
93    if (store.getters['authentication/isLoggedIn']) {
94      next();
95      return;
96    }
97    next('/login');
98  } else {
99    next();
100  }
101});
102
103export default router;
104