File tree 3 files changed +23
-3
lines changed
3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Router from 'vue-router'
3
3
import Content from './Content'
4
4
import ClientOnly from './ClientOnly'
5
5
import dataMixin from './dataMixin'
6
+ import store from './store'
6
7
import NotFound from '@notFound'
7
8
import { routes } from '@temp/routes'
8
9
import { siteData } from '@temp/siteData'
@@ -57,7 +58,12 @@ export function createApp () {
57
58
if ( saved ) {
58
59
return saved
59
60
} else if ( to . hash ) {
60
- return false
61
+ if ( store . disableScrollBehavior ) {
62
+ return false
63
+ }
64
+ return {
65
+ selector : to . hash
66
+ }
61
67
} else {
62
68
return { x : 0 , y : 0 }
63
69
}
Original file line number Diff line number Diff line change
1
+ // It is not yet time to use Vuex to manage the global state
2
+ // singleton object as a global store.
3
+ const state = {
4
+ disableScrollBehavior : false
5
+ }
6
+
7
+ export default state
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import Navbar from './Navbar.vue'
28
28
import Page from ' ./Page.vue'
29
29
import Sidebar from ' ./Sidebar.vue'
30
30
import { pathToComponentName } from ' @app/util'
31
+ import store from ' @app/store'
31
32
import { resolveSidebarItems } from ' ./util'
32
33
import throttle from ' lodash.throttle'
33
34
@@ -165,7 +166,7 @@ export default {
165
166
const sidebarLinks = [].slice .call (document .querySelectorAll (' .sidebar-link' ))
166
167
const anchors = [].slice .call (document .querySelectorAll (' .header-anchor' ))
167
168
.filter (anchor => sidebarLinks .some (sidebarLink => sidebarLink .hash === anchor .hash ))
168
-
169
+
169
170
const scrollTop = Math .max (window .pageYOffset , document .documentElement .scrollTop , document .body .scrollTop )
170
171
171
172
for (let i = 0 ; i < anchors .length ; i++ ) {
@@ -177,7 +178,13 @@ export default {
177
178
(! nextAnchor || scrollTop < nextAnchor .parentElement .offsetTop - 10 ))
178
179
179
180
if (isActive && this .$route .hash !== anchor .hash ) {
180
- this .$router .replace (anchor .hash )
181
+ store .disableScrollBehavior = true
182
+ this .$router .replace (anchor .hash , () => {
183
+ // execute after scrollBehavior handler.
184
+ this .$nextTick (() => {
185
+ store .disableScrollBehavior = false
186
+ })
187
+ })
181
188
return
182
189
}
183
190
}
You can’t perform that action at this time.
0 commit comments