Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 1 | import Vue from 'vue'; |
| 2 | import VueRouter from 'vue-router'; |
Yoshie Muranaka | 8263d85 | 2020-10-16 07:58:06 -0700 | [diff] [blame^] | 3 | |
| 4 | //Do not change store or routes import. |
| 5 | //Exact match alias set to support |
| 6 | //dotenv customizations. |
Yoshie Muranaka | 816d947 | 2020-09-03 11:19:28 -0700 | [diff] [blame] | 7 | import routes from './routes'; |
Yoshie Muranaka | 8263d85 | 2020-10-16 07:58:06 -0700 | [diff] [blame^] | 8 | import store from '../store'; |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 9 | |
| 10 | Vue.use(VueRouter); |
| 11 | |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 12 | const router = new VueRouter({ |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 13 | base: process.env.BASE_URL, |
| 14 | routes, |
Yoshie Muranaka | 71ac230 | 2019-12-26 11:43:36 -0800 | [diff] [blame] | 15 | linkExactActiveClass: 'nav-link--current' |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 16 | }); |
| 17 | |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 18 | router.beforeEach((to, from, next) => { |
| 19 | if (to.matched.some(record => record.meta.requiresAuth)) { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 20 | if (store.getters['authentication/isLoggedIn']) { |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 21 | next(); |
| 22 | return; |
| 23 | } |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame] | 24 | next('/login'); |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 25 | } else { |
| 26 | next(); |
| 27 | } |
| 28 | }); |
| 29 | |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 30 | export default router; |