Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 1 | import Vue from 'vue'; |
| 2 | import VueRouter from 'vue-router'; |
| 3 | import store from '../store/index'; |
| 4 | import AppLayout from '../layouts/AppLayout.vue'; |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 5 | |
| 6 | Vue.use(VueRouter); |
| 7 | |
| 8 | const routes = [ |
| 9 | { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 10 | path: '/', |
| 11 | name: '', |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 12 | meta: { |
| 13 | requiresAuth: true |
| 14 | }, |
| 15 | component: AppLayout, |
| 16 | children: [ |
| 17 | { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 18 | path: '', |
| 19 | component: () => import('@/views/Overview'), |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 20 | meta: { |
Yoshie Muranaka | 8d12910 | 2019-12-19 09:51:55 -0800 | [diff] [blame] | 21 | title: 'Overview' |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 22 | } |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 23 | }, |
| 24 | { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 25 | path: '/access-control/local-user-management', |
| 26 | name: 'local-users', |
| 27 | component: () => import('@/views/AccessControl/LocalUserManagement'), |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 28 | meta: { |
Yoshie Muranaka | 8d12910 | 2019-12-19 09:51:55 -0800 | [diff] [blame] | 29 | title: 'Local user management' |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 30 | } |
Derick Montague | 126eaab | 2019-12-23 13:33:52 -0600 | [diff] [blame^] | 31 | }, |
| 32 | { |
| 33 | path: '/unauthorized', |
| 34 | name: 'unauthorized', |
| 35 | component: () => import('@/views/Unauthorized'), |
| 36 | meta: { |
| 37 | title: 'Unauthorized' |
| 38 | } |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 39 | } |
| 40 | ] |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 41 | }, |
| 42 | { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 43 | path: '/login', |
| 44 | name: 'login', |
| 45 | component: () => import('@/views/Login'), |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 46 | meta: { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 47 | title: 'Login' |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 48 | } |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 49 | } |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 50 | ]; |
| 51 | |
| 52 | const router = new VueRouter({ |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 53 | base: process.env.BASE_URL, |
| 54 | routes, |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 55 | linkExactActiveClass: 'nav__link--current' |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 56 | }); |
| 57 | |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 58 | router.beforeEach((to, from, next) => { |
| 59 | if (to.matched.some(record => record.meta.requiresAuth)) { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 60 | if (store.getters['authentication/isLoggedIn']) { |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 61 | next(); |
| 62 | return; |
| 63 | } |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 64 | next('/login'); |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 65 | } else { |
| 66 | next(); |
| 67 | } |
| 68 | }); |
| 69 | |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 70 | export default router; |