import Vue from vue import Router from vue-router import store from st

 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
58
59
60
61
import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
const Index = () => import('@/pages/Index')
const Dashboard = () => import('@/pages/Dashboard')
const AddProfile = () => import('@/pages/AddProfile')
const ViewProfile = () => import('@/pages/ViewProfile')
const Auth = () => import('@/pages/Auth')
Vue.use(Router)
const router = new Router({
mode: 'history',
routes: [
{
path: '/',
name: 'home',
component: Index,
meta: {title: 'Главна страница'}
},
{
name: 'dashboard',
path: '/dashboard',
component: Dashboard,
meta: {title: 'Профайлы', requiresAuth: true}
},
{
name: 'add profile',
path: '/add',
component: AddProfile,
meta: {title: 'Добавить профайл', requiresAuth: true}
},
{
name: 'view profile',
path: '/profile/:id',
component: ViewProfile,
meta: {title: 'Профайл', requiresAuth: true},
children: [
{
name: 'edit profile',
path: 'edit'
}
]
},
{
name: 'auth',
path: '/auth',
component: Auth
}
]
})
router.beforeEach((to, from, next) => {
if (to.name !== 'home' && store.getters.checkUser) {
next({name: 'home'})
}
next()
})
export default router