Skip to content

Commit 4b8182f

Browse files
Move function
1 parent 49aa645 commit 4b8182f

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

client/router.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Vue from 'vue'
22
import Router from 'vue-router'
3+
import { scrollBehavior } from '~/utils'
34

45
Vue.use(Router)
56

@@ -33,24 +34,6 @@ const routes = [
3334
] }
3435
]
3536

36-
const scrollBehavior = (to, from, savedPosition) => {
37-
if (savedPosition) {
38-
return savedPosition
39-
}
40-
41-
let position = {}
42-
43-
if (to.matched.length < 2) {
44-
position = { x: 0, y: 0 }
45-
} else if (to.matched.some(r => r.components.default.options.scrollToTop)) {
46-
position = { x: 0, y: 0 }
47-
} if (to.hash) {
48-
position = { selector: to.hash }
49-
}
50-
51-
return position
52-
}
53-
5437
export function createRouter () {
5538
return new Router({
5639
routes,

client/utils/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,24 @@ export function cookieFromRequest (req, key) {
1818
return cookie.split('=')[1]
1919
}
2020
}
21+
22+
/**
23+
* https://router.vuejs.org/en/advanced/scroll-behavior.html
24+
*/
25+
export function scrollBehavior (to, from, savedPosition) {
26+
if (savedPosition) {
27+
return savedPosition
28+
}
29+
30+
let position = {}
31+
32+
if (to.matched.length < 2) {
33+
position = { x: 0, y: 0 }
34+
} else if (to.matched.some(r => r.components.default.options.scrollToTop)) {
35+
position = { x: 0, y: 0 }
36+
} if (to.hash) {
37+
position = { selector: to.hash }
38+
}
39+
40+
return position
41+
}

0 commit comments

Comments
 (0)