blob: 61cb9023fc9c77124a364921b59d61177f8250e8 [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: {
Yoshie Muranaka8d129102019-12-19 09:51:55 -080021 title: '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: {
Yoshie Muranaka8d129102019-12-19 09:51:55 -080029 title: 'Local user management'
Derick Montaguec8636e52019-12-06 01:28:38 -060030 }
Derick Montague126eaab2019-12-23 13:33:52 -060031 },
32 {
33 path: '/unauthorized',
34 name: 'unauthorized',
35 component: () => import('@/views/Unauthorized'),
36 meta: {
37 title: 'Unauthorized'
38 }
Derick Montaguee080a1a2019-12-04 16:30:08 -060039 }
40 ]
Derick Montaguea2988f42020-01-17 13:46:30 -060041 },
42 {
Derick Montaguefded0d12019-12-11 06:16:40 -060043 path: '/login',
44 name: 'login',
45 component: () => import('@/views/Login'),
Derick Montaguec8636e52019-12-06 01:28:38 -060046 meta: {
Derick Montaguefded0d12019-12-11 06:16:40 -060047 title: 'Login'
Derick Montaguec8636e52019-12-06 01:28:38 -060048 }
Derick Montaguea2988f42020-01-17 13:46:30 -060049 }
Derick Montaguea2988f42020-01-17 13:46:30 -060050];
51
52const router = new VueRouter({
Derick Montaguea2988f42020-01-17 13:46:30 -060053 base: process.env.BASE_URL,
54 routes,
Derick Montaguefded0d12019-12-11 06:16:40 -060055 linkExactActiveClass: 'nav__link--current'
Derick Montaguea2988f42020-01-17 13:46:30 -060056});
57
Derick Montaguee080a1a2019-12-04 16:30:08 -060058router.beforeEach((to, from, next) => {
59 if (to.matched.some(record => record.meta.requiresAuth)) {
Derick Montaguefded0d12019-12-11 06:16:40 -060060 if (store.getters['authentication/isLoggedIn']) {
Derick Montaguee080a1a2019-12-04 16:30:08 -060061 next();
62 return;
63 }
Derick Montaguefded0d12019-12-11 06:16:40 -060064 next('/login');
Derick Montaguee080a1a2019-12-04 16:30:08 -060065 } else {
66 next();
67 }
68});
69
Derick Montaguea2988f42020-01-17 13:46:30 -060070export default router;