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/reboot-bmc', 60 name: 'reboot-bmc', 61 component: () => import('@/views/Control/RebootBmc'), 62 meta: { 63 title: 'appPageTitle.rebootBmc' 64 } 65 }, 66 { 67 path: '/control/server-power-operations', 68 name: 'server-power-operations', 69 component: () => import('@/views/Control/ServerPowerOperations'), 70 meta: { 71 title: 'appPageTitle.serverPowerOperations' 72 } 73 }, 74 { 75 path: '/unauthorized', 76 name: 'unauthorized', 77 component: () => import('@/views/Unauthorized'), 78 meta: { 79 title: 'appPageTitle.unauthorized' 80 } 81 } 82 ] 83 }, 84 { 85 path: '/login', 86 name: 'login', 87 component: () => import('@/views/Login'), 88 meta: { 89 title: 'appPageTitle.login' 90 } 91 } 92]; 93 94const router = new VueRouter({ 95 base: process.env.BASE_URL, 96 routes, 97 linkExactActiveClass: 'nav-link--current' 98}); 99 100router.beforeEach((to, from, next) => { 101 // Commit logout to remove XSRF-TOKEN cookie when 102 // redirected to login page (eg 401 response) 103 if (to.name === 'login') store.commit('authentication/logout'); 104 if (to.matched.some(record => record.meta.requiresAuth)) { 105 if (store.getters['authentication/isLoggedIn']) { 106 next(); 107 return; 108 } 109 next('/login'); 110 } else { 111 next(); 112 } 113}); 114 115export default router; 116