-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathrouter.js
57 lines (53 loc) · 1.24 KB
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import Vue from 'vue';
import Router from 'vue-router';
import Home from './views/Home.vue';
import store from '@/store.js';
Vue.use(Router);
const router = new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/about',
name: 'about',
component: () => import('./views/About.vue'),
meta: {
authRequired: true
}
},
{
path: '/menu',
name: 'menu',
component: () => import('./views/Menu.vue')
},
{
path: '/sign-in',
name: 'signin',
component: () => import('./views/Signin.vue')
},
{
path: '/join',
name: 'join',
component: () => import('./views/Join.vue')
}
]
});
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.authRequired)) {
if (!store.state.isAuthenticated) {
next({
path: '/sign-in'
});
} else {
next();
}
} else {
next();
}
});
export default router;