xref: /openbmc/webui-vue/src/router/index.js (revision ce9a3ef3036923cb4c0f28240c8bb37a6b4540fc)
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    meta: {
14      requiresAuth: true
15    },
16    component: AppLayout,
17    children: [
18      {
19        path: '',
20        name: 'overview',
21        component: () => import('@/views/Overview'),
22        meta: {
23          title: 'appPageTitle.overview'
24        }
25      },
26      {
27        path: '/health/sensors',
28        name: 'sensors',
29        component: () => import('@/views/Health/Sensors'),
30        meta: {
31          title: 'appPageTitle.sensors'
32        }
33      },
34      {
35        path: '/access-control/ldap',
36        name: 'ldap',
37        component: () => import('@/views/AccessControl/Ldap'),
38        meta: {
39          title: 'appPageTitle.ldap'
40        }
41      },
42      {
43        path: '/access-control/local-user-management',
44        name: 'local-users',
45        component: () => import('@/views/AccessControl/LocalUserManagement'),
46        meta: {
47          title: 'appPageTitle.localUserManagement'
48        }
49      },
50      {
51        path: '/access-control/ssl-certificates',
52        name: 'ssl-certificates',
53        component: () => import('@/views/AccessControl/SslCertificates'),
54        meta: {
55          title: 'appPageTitle.sslCertificates'
56        }
57      },
58      {
59        path: '/control/manage-power-usage',
60        name: 'manage-power-usage',
61        component: () => import('@/views/Control/ManagePowerUsage'),
62        meta: {
63          title: 'appPageTitle.managePowerUsage'
64        }
65      },
66      {
67        path: '/control/reboot-bmc',
68        name: 'reboot-bmc',
69        component: () => import('@/views/Control/RebootBmc'),
70        meta: {
71          title: 'appPageTitle.rebootBmc'
72        }
73      },
74      {
75        path: '/control/server-led',
76        name: 'server-led',
77        component: () => import('@/views/Control/ServerLed'),
78        meta: {
79          title: 'appPageTitle.serverLed'
80        }
81      },
82      {
83        path: '/control/server-power-operations',
84        name: 'server-power-operations',
85        component: () => import('@/views/Control/ServerPowerOperations'),
86        meta: {
87          title: 'appPageTitle.serverPowerOperations'
88        }
89      },
90      {
91        path: '/unauthorized',
92        name: 'unauthorized',
93        component: () => import('@/views/Unauthorized'),
94        meta: {
95          title: 'appPageTitle.unauthorized'
96        }
97      }
98    ]
99  },
100  {
101    path: '/login',
102    name: 'login',
103    component: () => import('@/views/Login'),
104    meta: {
105      title: 'appPageTitle.login'
106    }
107  }
108];
109
110const router = new VueRouter({
111  base: process.env.BASE_URL,
112  routes,
113  linkExactActiveClass: 'nav-link--current'
114});
115
116router.beforeEach((to, from, next) => {
117  if (to.matched.some(record => record.meta.requiresAuth)) {
118    if (store.getters['authentication/isLoggedIn']) {
119      next();
120      return;
121    }
122    next('/login');
123  } else {
124    next();
125  }
126});
127
128export default router;
129