diff --git a/docs/default-theme-config/README.md b/docs/default-theme-config/README.md index 650dddfe36..b803f57003 100644 --- a/docs/default-theme-config/README.md +++ b/docs/default-theme-config/README.md @@ -142,6 +142,18 @@ sidebarDepth: 2 --- ``` +### Active Header Links + +By default, the nested header links and the hash in the URL are updated as the user scrolls to view the different sections of the page. This behavior can be disabled with the following theme config: + +``` js +module.exports = { + themeConfig: { + disableActiveHash: true, // boolean + } +} +``` + ### Sidebar Groups You can divide sidebar links into multiple groups by using objects: diff --git a/lib/default-theme/Layout.vue b/lib/default-theme/Layout.vue index c794f6a753..bca4c1168e 100644 --- a/lib/default-theme/Layout.vue +++ b/lib/default-theme/Layout.vue @@ -136,6 +136,10 @@ export default { this.setActiveHash() }, 300), setActiveHash () { + if (this.$site.themeConfig.disableActiveHash) { + return + } + const sidebarLinks = [].slice.call(document.querySelectorAll('.sidebar-link')) const anchors = [].slice.call(document.querySelectorAll('.header-anchor')) .filter(anchor => sidebarLinks.some(sidebarLink => sidebarLink.hash === anchor.hash))