Repository navigation
Expand file tree
/
Copy pathrouter.js
More file actions
96 lines (85 loc) · 2.73 KB
/
Copy pathrouter.js
File metadata and controls
96 lines (85 loc) · 2.73 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
const PageHome = () => import(/* webpackChunkName: "page-home" */ '@/pages/Home.vue').then((m) => m.default || m);
const PageArchive = () => import(/* webpackChunkName: "page-archive" */ '@/pages/Archive.vue').then((m) => m.default || m);
const PageSingle = () => import(/* webpackChunkName: "page-single" */ '@/pages/Single.vue').then((m) => m.default || m);
const PageSliderTest = () => import(/* webpackChunkName: "page-slider-test" */ '@/pages/SliderTest.vue').then((m) => m.default || m);
const createRouter = () => new Router({
mode: 'history',
scrollBehavior(to, from, savedPosition) {
let output = { x: 0, y: 0 };
if (from.hash) output = null;
if (savedPosition) output = savedPosition;
if (to.hash) {
const isHashBlacklisted = to.hash.indexOf('=') > -1;
let selector = to.hash;
if (isHashBlacklisted) selector = null;
output = { selector };
}
return output;
},
routes: [
// homepage
{
name: 'Home',
path: '/',
component: PageHome,
},
{
path: '/page/1/',
pathToRegexpOptions: { strict: true },
redirect: '/',
},
{
name: 'HomePaged',
path: '/page/:id/',
pathToRegexpOptions: { strict: true },
component: PageHome,
meta: {
class: 'home',
},
},
// tests
// {
// name: 'SliderTest',
// path: '/slider-test/',
// component: PageSliderTest,
// },
// archive
{
path: '/(category|tag)',
redirect: '/',
},
{
path: '/(category|tag)/:slug+/(page|page/1)',
redirect: (to) => `/${to.params.pathMatch}/${to.params.slug}/`,
},
{
path: '/(category|tag)/:slug+',
pathToRegexpOptions: { strict: true },
redirect: (to) => `/${to.params.pathMatch}/${to.params.slug}/`,
},
{
name: 'Archive',
path: '/(category|tag)/:slug+/',
pathToRegexpOptions: { strict: true },
component: PageArchive,
},
// single
{
name: 'Single',
path: '/:singleSlug/',
alias: [
'/:singleSlug/*',
],
pathToRegexpOptions: { strict: true },
component: PageSingle,
},
{
path: '/:singleSlug',
redirect: { name: 'Single' },
},
],
});
export { createRouter }; // eslint-disable-line import/prefer-default-export