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 8const routes = [ 9 { 10 path: '/', 11 name: '', 12 meta: { 13 requiresAuth: true 14 }, 15 component: AppLayout, 16 children: [ 17 { 18 path: '', 19 component: () => import('@/views/Overview'), 20 meta: { 21 title: 'Overview' 22 } 23 }, 24 { 25 path: '/access-control/local-user-management', 26 name: 'local-users', 27 component: () => import('@/views/AccessControl/LocalUserManagement'), 28 meta: { 29 title: 'Local user management' 30 } 31 }, 32 { 33 path: '/unauthorized', 34 name: 'unauthorized', 35 component: () => import('@/views/Unauthorized'), 36 meta: { 37 title: 'Unauthorized' 38 } 39 } 40 ] 41 }, 42 { 43 path: '/login', 44 name: 'login', 45 component: () => import('@/views/Login'), 46 meta: { 47 title: 'Login' 48 } 49 } 50]; 51 52const router = new VueRouter({ 53 base: process.env.BASE_URL, 54 routes, 55 linkExactActiveClass: 'nav-link--current' 56}); 57 58router.beforeEach((to, from, next) => { 59 if (to.matched.some(record => record.meta.requiresAuth)) { 60 if (store.getters['authentication/isLoggedIn']) { 61 next(); 62 return; 63 } 64 next('/login'); 65 } else { 66 next(); 67 } 68}); 69 70export default router; 71