Skip to content

Commit 27b54e9

Browse files
authored
Ensure that doc url hash IDs are scrolled to on page load (#4329)
2 parents 3c245a7 + 9202f52 commit 27b54e9

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

docs/index.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
shouldStable: false,
109109
version: versionNumber,
110110
oldVersion: undefined,
111-
versionOptions: ['master']
111+
versionOptions: ['master'],
112+
scrolledOnce: false,
112113
},
113114
asyncComputed: {
114115
async outputHtml() {
@@ -158,7 +159,7 @@
158159
renderer.heading = function(text, level) {
159160
const id = htmlToId(text);
160161
return `<h${level}>
161-
<a href="#${id}" name="${id}" class="header-link">${text}</a>
162+
<a id="${id}" href="#${id}" name="${id}" class="header-link">${text}</a>
162163
</h${level}>`;
163164
};
164165

@@ -186,12 +187,15 @@
186187
.filter(tag => tag.startsWith('v'));
187188
this.versionOptions = this.versionOptions.concat(tagOptions);
188189
},
189-
mounted() {
190+
updated() {
190191
if (UrlHash === '') return;
191-
const target = document.querySelector(`#${UrlHash}`);
192-
if (target != null) {
193-
target.scrollIntoView(true);
194-
}
192+
this.$nextTick(() => {
193+
const target = document.querySelector(`#${UrlHash}`);
194+
if (target != null && !this.scrolledOnce) {
195+
target.scrollIntoView(true);
196+
this.scrolledOnce = true;
197+
}
198+
});
195199
},
196200
methods: {
197201
handleReqFailure(e) {

0 commit comments

Comments
 (0)