Repository navigation
Expand file tree
/
Copy pathrouter.js
More file actions
55 lines (47 loc) · 1.36 KB
/
Copy pathrouter.js
File metadata and controls
55 lines (47 loc) · 1.36 KB
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
import Vue from 'vue'
import Router from 'vue-router'
function route (path, file, name, children) {
return {
exact: true,
path,
name,
children,
component: require(`./pages/${file}.vue`)
}
}
Vue.use(Router)
const router = new Router({
base: __dirname,
mode: 'hash',
scrollBehavior: () => ({ y: 0 }),
routes: [
route('/login', 'Login', 'login'),
route('/error', 'Error', 'error'),
// path, file(*.vue), name, children
route('/', 'Main', null, [
route('/', 'Home', 'home'),
route('/crud/:resource', 'CrudGrid', 'grid'),
route('/crud/:resource/:id/edit', 'CrudForm', 'edit'),
route('/crud/:resource/create', 'CrudForm', 'create'),
route('/crud/:resource/:id/:action', 'CrudForm', 'action'),
route('/crud/:resource/:action', 'CrudForm', 'indexAction'),
route('/example', 'Example'),
route('/settings', 'Settings'),
route('/theme', 'Theme'),
route('/chat', 'Chat'),
route('/about', 'About')
]),
// Global redirect for 404
{ path: '*', redirect: '/error', query: {code: 404, message: 'Page Not Found.'} }
]
})
router.beforeEach((to, from, next) => {
global.store.dispatch('checkPageTitle', to.path)
/* eslint-disable no-undef */
if (typeof ga !== 'undefined') {
ga('set', 'page', to.path)
ga('send', 'pageview')
}
next()
})
export default router