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