1import Vue from 'vue'; 2import VueRouter from 'vue-router'; 3import store from '../store/index'; 4import AppLayout from '../layouts/AppLayout.vue'; 5import LoginLayout from '@/layouts/LoginLayout'; 6import ConsoleLayout from '@/layouts/ConsoleLayout.vue'; 7 8Vue.use(VueRouter); 9 10// Meta title is translated using i18n in App.vue and PageTitle.Vue 11// Example meta: {title: 'appPageTitle.overview'} 12const routes = [ 13 { 14 path: '/', 15 meta: { 16 requiresAuth: true 17 }, 18 component: AppLayout, 19 children: [ 20 { 21 path: '', 22 name: 'overview', 23 component: () => import('@/views/Overview'), 24 meta: { 25 title: 'appPageTitle.overview' 26 } 27 }, 28 { 29 path: '/profile-settings', 30 name: 'profile-settings', 31 component: () => import('@/views/ProfileSettings'), 32 meta: { 33 title: 'appPageTitle.profileSettings' 34 } 35 }, 36 { 37 path: '/health/event-logs', 38 name: 'event-logs', 39 component: () => import('@/views/Health/EventLogs'), 40 meta: { 41 title: 'appPageTitle.eventLogs' 42 } 43 }, 44 { 45 path: '/health/hardware-status', 46 name: 'hardware-status', 47 component: () => import('@/views/Health/HardwareStatus'), 48 meta: { 49 title: 'appPageTitle.hardwareStatus' 50 } 51 }, 52 { 53 path: '/health/sensors', 54 name: 'sensors', 55 component: () => import('@/views/Health/Sensors'), 56 meta: { 57 title: 'appPageTitle.sensors' 58 } 59 }, 60 { 61 path: '/access-control/ldap', 62 name: 'ldap', 63 component: () => import('@/views/AccessControl/Ldap'), 64 meta: { 65 title: 'appPageTitle.ldap' 66 } 67 }, 68 { 69 path: '/access-control/local-user-management', 70 name: 'local-users', 71 component: () => import('@/views/AccessControl/LocalUserManagement'), 72 meta: { 73 title: 'appPageTitle.localUserManagement' 74 } 75 }, 76 { 77 path: '/access-control/ssl-certificates', 78 name: 'ssl-certificates', 79 component: () => import('@/views/AccessControl/SslCertificates'), 80 meta: { 81 title: 'appPageTitle.sslCertificates' 82 } 83 }, 84 { 85 path: '/configuration/date-time-settings', 86 name: 'date-time-settings', 87 component: () => import('@/views/Configuration/DateTimeSettings'), 88 meta: { 89 title: 'appPageTitle.dateTimeSettings' 90 } 91 }, 92 { 93 path: '/control/manage-power-usage', 94 name: 'manage-power-usage', 95 component: () => import('@/views/Control/ManagePowerUsage'), 96 meta: { 97 title: 'appPageTitle.managePowerUsage' 98 } 99 }, 100 { 101 path: '/configuration/network-settings', 102 name: 'network-settings', 103 component: () => import('@/views/Configuration/NetworkSettings'), 104 meta: { 105 title: 'appPageTitle.networkSettings' 106 } 107 }, 108 { 109 path: '/control/reboot-bmc', 110 name: 'reboot-bmc', 111 component: () => import('@/views/Control/RebootBmc'), 112 meta: { 113 title: 'appPageTitle.rebootBmc' 114 } 115 }, 116 { 117 path: '/control/server-led', 118 name: 'server-led', 119 component: () => import('@/views/Control/ServerLed'), 120 meta: { 121 title: 'appPageTitle.serverLed' 122 } 123 }, 124 { 125 path: '/control/serial-over-lan', 126 name: 'serial-over-lan', 127 component: () => import('@/views/Control/SerialOverLan'), 128 meta: { 129 title: 'appPageTitle.serialOverLan' 130 } 131 }, 132 { 133 path: '/control/server-power-operations', 134 name: 'server-power-operations', 135 component: () => import('@/views/Control/ServerPowerOperations'), 136 meta: { 137 title: 'appPageTitle.serverPowerOperations' 138 } 139 }, 140 { 141 path: '/unauthorized', 142 name: 'unauthorized', 143 component: () => import('@/views/Unauthorized'), 144 meta: { 145 title: 'appPageTitle.unauthorized' 146 } 147 } 148 ] 149 }, 150 { 151 path: '/login', 152 component: LoginLayout, 153 children: [ 154 { 155 path: '', 156 name: 'login', 157 component: () => import('@/views/Login'), 158 meta: { 159 title: 'appPageTitle.login' 160 } 161 } 162 ] 163 }, 164 { 165 path: '/console', 166 component: ConsoleLayout, 167 meta: { 168 requiresAuth: true 169 }, 170 children: [ 171 { 172 path: '/console/serial-over-lan-console', 173 name: 'serial-over-lan', 174 component: () => 175 import('@/views/Control/SerialOverLan/SerialOverLanConsole'), 176 meta: { 177 title: 'appPageTitle.serialOverLan' 178 } 179 } 180 ] 181 } 182]; 183 184const router = new VueRouter({ 185 base: process.env.BASE_URL, 186 routes, 187 linkExactActiveClass: 'nav-link--current' 188}); 189 190router.beforeEach((to, from, next) => { 191 if (to.matched.some(record => record.meta.requiresAuth)) { 192 if (store.getters['authentication/isLoggedIn']) { 193 next(); 194 return; 195 } 196 next('/login'); 197 } else { 198 next(); 199 } 200}); 201 202export default router; 203