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/event-logs', 28 name: 'event-logs', 29 component: () => import('@/views/Health/EventLogs'), 30 meta: { 31 title: 'appPageTitle.eventLogs' 32 } 33 }, 34 { 35 path: '/health/sensors', 36 name: 'sensors', 37 component: () => import('@/views/Health/Sensors'), 38 meta: { 39 title: 'appPageTitle.sensors' 40 } 41 }, 42 { 43 path: '/access-control/ldap', 44 name: 'ldap', 45 component: () => import('@/views/AccessControl/Ldap'), 46 meta: { 47 title: 'appPageTitle.ldap' 48 } 49 }, 50 { 51 path: '/access-control/local-user-management', 52 name: 'local-users', 53 component: () => import('@/views/AccessControl/LocalUserManagement'), 54 meta: { 55 title: 'appPageTitle.localUserManagement' 56 } 57 }, 58 { 59 path: '/access-control/ssl-certificates', 60 name: 'ssl-certificates', 61 component: () => import('@/views/AccessControl/SslCertificates'), 62 meta: { 63 title: 'appPageTitle.sslCertificates' 64 } 65 }, 66 { 67 path: '/control/manage-power-usage', 68 name: 'manage-power-usage', 69 component: () => import('@/views/Control/ManagePowerUsage'), 70 meta: { 71 title: 'appPageTitle.managePowerUsage' 72 } 73 }, 74 { 75 path: '/configuration/network-settings', 76 name: 'network-settings', 77 component: () => import('@/views/Configuration/NetworkSettings'), 78 meta: { 79 title: 'appPageTitle.networkSettings' 80 } 81 }, 82 { 83 path: '/control/reboot-bmc', 84 name: 'reboot-bmc', 85 component: () => import('@/views/Control/RebootBmc'), 86 meta: { 87 title: 'appPageTitle.rebootBmc' 88 } 89 }, 90 { 91 path: '/control/server-led', 92 name: 'server-led', 93 component: () => import('@/views/Control/ServerLed'), 94 meta: { 95 title: 'appPageTitle.serverLed' 96 } 97 }, 98 { 99 path: '/control/server-power-operations', 100 name: 'server-power-operations', 101 component: () => import('@/views/Control/ServerPowerOperations'), 102 meta: { 103 title: 'appPageTitle.serverPowerOperations' 104 } 105 }, 106 { 107 path: '/unauthorized', 108 name: 'unauthorized', 109 component: () => import('@/views/Unauthorized'), 110 meta: { 111 title: 'appPageTitle.unauthorized' 112 } 113 } 114 ] 115 }, 116 { 117 path: '/login', 118 name: 'login', 119 component: () => import('@/views/Login'), 120 meta: { 121 title: 'appPageTitle.login' 122 } 123 } 124]; 125 126const router = new VueRouter({ 127 base: process.env.BASE_URL, 128 routes, 129 linkExactActiveClass: 'nav-link--current' 130}); 131 132router.beforeEach((to, from, next) => { 133 if (to.matched.some(record => record.meta.requiresAuth)) { 134 if (store.getters['authentication/isLoggedIn']) { 135 next(); 136 return; 137 } 138 next('/login'); 139 } else { 140 next(); 141 } 142}); 143 144export default router; 145