-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to scroll to anchor #2562
Comments
I think it has to do with scrollBehavior in core/lib/client/app.js -> createApp -> router = newRouter It returns a selector of to.hash for scroll point. However, the hash is encodedURI, you can see it in router section of the vue debug tool. I think the selector should return decodeURI(to.hash) for satety. |
@dos077 Is it more appropriate to consider using the |
Right, there maybe special characters used in the hash. Fixed. |
I wonder if #2558 is related to this issue somehow. No non-ANSI characters in my case, though. |
@elringus |
Does #2566 actually fix this? |
I also have the same problem, before #2566 is merged, can temporarily solve it with the following code:
.vuepress/theme/components/Layout.vue <script>
// ...
export default {
// ...
methods: {
scrollTo(selector) {
if (!selector || selector === '#') return
const el = document.querySelector(decodeURIComponent(selector))
if (el && el.offsetTop) {
window.scrollTo(0, el.offsetTop)
}
}
},
mounted() {
this.scrollTo(location.hash)
}
}
</script> |
Just want to share my workaround: // enhanceApp.js
export default () => {
if (typeof document === 'undefined') return
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
const { hash } = location
const decoded = decodeURIComponent(hash)
if (hash !== decoded) {
document.querySelector(decoded).scrollIntoView()
}
}
}
} |
Closed by #2639 |
This fixed my issue, thanks! I am wondering why the author dose not fix this long-lasting bug? |
how can fix it for vuepress version 2.0.0-rc.7? |
Bug report
Steps to reproduce
vuepress dev
What is expected?
The browser should display the page scrolled at that 关于我 title position.
What is actually happening?
No reaction, at the top
Other relevant information
The title contains non ANSI characters
Console error:
npx vuepress info
in my VuePress project:The text was updated successfully, but these errors were encountered: