blob: 99f2a12fe421da06014d75ad42d12d41869795d2 [file] [log] [blame]
Derick Montaguefded0d12019-12-11 06:16:40 -06001import Vue from 'vue';
2import VueRouter from 'vue-router';
3import store from '../store/index';
4import AppLayout from '../layouts/AppLayout.vue';
Derick Montaguea2988f42020-01-17 13:46:30 -06005
6Vue.use(VueRouter);
7
8const routes = [
9 {
Derick Montaguefded0d12019-12-11 06:16:40 -060010 path: '/',
11 name: '',
Derick Montaguee080a1a2019-12-04 16:30:08 -060012 meta: {
13 requiresAuth: true
14 },
15 component: AppLayout,
16 children: [
17 {
Derick Montaguefded0d12019-12-11 06:16:40 -060018 path: '',
19 component: () => import('@/views/Overview'),
Derick Montaguec8636e52019-12-06 01:28:38 -060020 meta: {
Derick Montaguefded0d12019-12-11 06:16:40 -060021 title: 'Server Overview'
Derick Montaguec8636e52019-12-06 01:28:38 -060022 }
Derick Montaguee080a1a2019-12-04 16:30:08 -060023 },
24 {
Derick Montaguefded0d12019-12-11 06:16:40 -060025 path: '/access-control/local-user-management',
26 name: 'local-users',
27 component: () => import('@/views/AccessControl/LocalUserManagement'),
Derick Montaguec8636e52019-12-06 01:28:38 -060028 meta: {
Derick Montaguefded0d12019-12-11 06:16:40 -060029 title: 'Manage Local Users'
Derick Montaguec8636e52019-12-06 01:28:38 -060030 }
Derick Montaguee080a1a2019-12-04 16:30:08 -060031 }
32 ]
Derick Montaguea2988f42020-01-17 13:46:30 -060033 },
34 {
Derick Montaguefded0d12019-12-11 06:16:40 -060035 path: '/login',
36 name: 'login',
37 component: () => import('@/views/Login'),
Derick Montaguec8636e52019-12-06 01:28:38 -060038 meta: {
Derick Montaguefded0d12019-12-11 06:16:40 -060039 title: 'Login'
Derick Montaguec8636e52019-12-06 01:28:38 -060040 }
Derick Montaguea2988f42020-01-17 13:46:30 -060041 }
Derick Montaguea2988f42020-01-17 13:46:30 -060042];
43
44const router = new VueRouter({
Derick Montaguea2988f42020-01-17 13:46:30 -060045 base: process.env.BASE_URL,
46 routes,
Derick Montaguefded0d12019-12-11 06:16:40 -060047 linkExactActiveClass: 'nav__link--current'
Derick Montaguea2988f42020-01-17 13:46:30 -060048});
49
Derick Montaguee080a1a2019-12-04 16:30:08 -060050router.beforeEach((to, from, next) => {
51 if (to.matched.some(record => record.meta.requiresAuth)) {
Derick Montaguefded0d12019-12-11 06:16:40 -060052 if (store.getters['authentication/isLoggedIn']) {
Derick Montaguee080a1a2019-12-04 16:30:08 -060053 next();
54 return;
55 }
Derick Montaguefded0d12019-12-11 06:16:40 -060056 next('/login');
Derick Montaguee080a1a2019-12-04 16:30:08 -060057 } else {
58 next();
59 }
60});
61
Derick Montaguea2988f42020-01-17 13:46:30 -060062export default router;