Skip to content

Commit 552565c

Browse files
committed
Fix pages not loading on correct anchor
vuejs/vuepress#1499
1 parent cd616ae commit 552565c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/.vuepress/config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ module.exports = {
1616
head: [
1717
['meta', {name: 'theme-color', content: '#3eaf7c'}],
1818
['meta', {name: 'apple-mobile-web-app-capable', content: 'yes'}],
19-
['meta', {name: 'apple-mobile-web-app-status-bar-style', content: 'black'}]
19+
['meta', {name: 'apple-mobile-web-app-status-bar-style', content: 'black'}],
20+
['script', {src: '/js/fix-scroll-to-hash.js'}]
2021
],
2122

2223
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// https://github.com/vuejs/vuepress/issues/1499#issuecomment-663807385
2+
3+
window.onload = function() {
4+
requestAnimationFrame(function() {
5+
if (location.hash) {
6+
const element = document.getElementById(location.hash.slice(1));
7+
8+
if (element) {
9+
element.scrollIntoView();
10+
}
11+
}
12+
})
13+
};

0 commit comments

Comments
 (0)