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 path: '/change-password', 164 name: 'change-password', 165 component: () => import('@/views/ChangePassword'), 166 meta: { 167 title: 'appPageTitle.changePassword', 168 requiresAuth: true 169 } 170 } 171 ] 172 }, 173 { 174 path: '/console', 175 component: ConsoleLayout, 176 meta: { 177 requiresAuth: true 178 }, 179 children: [ 180 { 181 path: '/console/serial-over-lan-console', 182 name: 'serial-over-lan', 183 component: () => 184 import('@/views/Control/SerialOverLan/SerialOverLanConsole'), 185 meta: { 186 title: 'appPageTitle.serialOverLan' 187 } 188 } 189 ] 190 } 191]; 192 193const router = new VueRouter({ 194 base: process.env.BASE_URL, 195 routes, 196 linkExactActiveClass: 'nav-link--current' 197}); 198 199router.beforeEach((to, from, next) => { 200 if (to.matched.some(record => record.meta.requiresAuth)) { 201 if (store.getters['authentication/isLoggedIn']) { 202 next(); 203 return; 204 } 205 next('/login'); 206 } else { 207 next(); 208 } 209}); 210 211export default router; 212