1import Vue from 'vue'; 2import VueRouter from 'vue-router'; 3import store from '../store'; 4import routes from './routes'; 5 6Vue.use(VueRouter); 7 8const router = new VueRouter({ 9 base: process.env.BASE_URL, 10 routes, 11 linkExactActiveClass: 'nav-link--current' 12}); 13 14router.beforeEach((to, from, next) => { 15 if (to.matched.some(record => record.meta.requiresAuth)) { 16 if (store.getters['authentication/isLoggedIn']) { 17 next(); 18 return; 19 } 20 next('/login'); 21 } else { 22 next(); 23 } 24}); 25 26export default router; 27