File tree Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Original file line number Diff line number Diff line change 11import Vue from 'vue'
22import Router from 'vue-router'
3+ import { scrollBehavior } from '~/utils'
34
45Vue . 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-
5437export function createRouter ( ) {
5538 return new Router ( {
5639 routes,
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments