File tree 4 files changed +9
-36
lines changed
4 files changed +9
-36
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,15 @@ export function createApp (isServer) {
62
62
base : siteData . base ,
63
63
mode : 'history' ,
64
64
fallback : false ,
65
- routes
65
+ routes,
66
+ scrollBehavior ( to , from , savedPosition ) {
67
+ if ( savedPosition ) {
68
+ return savedPosition
69
+ }
70
+ if ( to . path !== from . path ) {
71
+ return { x : 0 , y : 0 }
72
+ }
73
+ }
66
74
} )
67
75
68
76
// redirect /foo to /foo/
Original file line number Diff line number Diff line change 1
- import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js'
2
-
3
1
export default {
4
2
created ( ) {
5
3
this . $vuepress . $on ( 'AsyncMarkdownContentMounted' , ( ) => {
6
4
this . $vuepress . $set ( 'contentMounted' , true )
7
-
8
- this . $smoothScroll = new SmoothScroll ( 'a[href*="#"]' , {
9
- speed : 1 ,
10
- speedAsDuration : true ,
11
- easing : 'easeInOutCubic'
12
- } )
13
-
14
- if ( this . $route . hash ) {
15
- const hash = decodeURIComponent ( this . $route . hash )
16
- try {
17
- const anchor = document . getElementById ( hash . slice ( 1 ) )
18
- const anchorLink = anchor . querySelector ( 'a.header-anchor' )
19
- setTimeout ( ( ) => {
20
- window . scroll ( {
21
- top : anchorLink . offsetTop - 70 ,
22
- left : 0 ,
23
- behavior : 'auto'
24
- } )
25
- } )
26
- } catch ( e ) {
27
- console . error ( e )
28
- }
29
- }
30
5
} )
31
6
} ,
32
7
33
8
watch : {
34
9
'$route.path' ( ) {
35
10
this . $vuepress . $set ( 'contentMounted' , false )
36
- this . $smoothScroll . destroy ( )
37
11
}
38
- } ,
39
-
40
- beforeDestroy ( ) {
41
- this . $smoothScroll . destroy ( )
42
12
}
43
13
}
Original file line number Diff line number Diff line change 55
55
"optimize-css-assets-webpack-plugin" : " ^4.0.0" ,
56
56
"portfinder" : " ^1.0.13" ,
57
57
"postcss-loader" : " ^2.1.5" ,
58
- "smooth-scroll" : " ^15.0.0" ,
59
58
"toml" : " ^2.3.3" ,
60
59
"url-loader" : " ^1.0.1" ,
61
60
"vue" : " ^2.5.16" ,
Original file line number Diff line number Diff line change 7606
7606
dependencies :
7607
7607
is-fullwidth-code-point "^2.0.0"
7608
7608
7609
- smooth-scroll@^15.0.0 :
7610
- version "15.0.0"
7611
- resolved "https://registry.yarnpkg.com/smooth-scroll/-/smooth-scroll-15.0.0.tgz#be4f9cb2cc4952d80db6736e5656ed5849305272"
7612
-
7613
7609
snapdragon-node@^2.0.1 :
7614
7610
version "2.1.1"
7615
7611
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"
You can’t perform that action at this time.
0 commit comments