-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
anchors do not work #5359
Comments
the workaround I found is to combine
|
Have you tried You can see the default scrollBehavior here and you can override this. I typically use something like this:
|
@danielroe I did know that it could be overrided, but default scrollBehavior looks fine to me... I'll try to play with this one. Playing with the repro link, |
Yes, I understand, and agree there's an issue. It looks like hashes work if the page changes (try clicking the link from |
It doesn't work in nuxt 2.4.5 too. On first load, no scroll behavior too. |
@danielroe exactly. clicking on an anchored link, scrolling back up and clicking again: 2nd time doesn't work. It might be an issue with vue-router though |
Also running into this issue with 2.5.1, but trying this workaround here for now: https://forum.vuejs.org/t/how-to-handle-anchors-bookmarks-with-vue-router/14563/5 (See 2nd last comment for solution) |
Thanks for your contribution to Nuxt.js!
Issues that are labeled as |
Nor of the suggested solutions works in latest nuxt version v2.10.0 |
Any chance of re-opening this issue as it has not been fixed and, based on @folamy 's comment, seems to have gotten worse? |
Thanks for your contribution to Nuxt.js!
Issues that are labeled as |
Any news on this issue ? Facing it on v2.11.0 |
Hi, I am quite a newbie with Nuxt JS, which is amazing btw. Cheers, Loris |
I'm also interested in seeing a "standard" solution to this. |
Thank you so much! This worked perfectly for me. |
A workaround can be to use VueScrollTo library. |
@danielroe Thanks, your solution seems to work. But this generates the issue, that nuxt will no longer scroll back to top on each route change automatically, even when using |
Is there any news on the standard and recommended (not a workaround) solution? |
Ok I had been struggling with this issue all day today, what I did is inserted the snippet I will leave below in my nuxt.config.js. The following way
}` |
I have confirmed that the anchor link transitions by the following method with reference to this.
|
Been almost 2 years now, any update? |
+1 |
Looking at this, it's an upstream issue in |
Workaround for me is just adding a method to the click: <nuxt-link
ref="calculator"
v-bind:to="{ path: '/', hash: '#calculator' }"
v-on:click.native="scrollToSection('#calculator')"
> scrollToSection(section) {
if (this.$nuxt.$route.name === 'index') {
const navHeight = document.getElementById('navigation').offsetHeight;
window.scrollTo({
top: document.querySelector(section).offsetTop - navHeight,
behavior: 'smooth',
});
}
}, Of course you can add this method globally and just pass the section on buttons clicks. |
NuxtLink hash scroll does not scroll back to the top of filter bar if user manually scrolled to bottom Related Issue: nuxt/nuxt#5359 Solution: Install vue-scrollto package and move scroll to element to outside of sticky element
got an issue if anchor tag is generated from kind of WYSISWYG editor from the CMS, when click all anchor tag with hash url it makes the page reload again |
@rolexta Make sure that the anchor doesn't include a "/" before the "#" |
Since then, I have confirmed that it works normally with nuxt v2.15.8 by the following method.
・ Anchor in the page
I would appreciate it if you could refer to it. ◆ app / router.scrollBehavior.js
◆ Target page.vue
|
I am running into this issue with Nuxt Bridge, using No matter what I do, the router never has a value for either this.$router.push({ to: '/some-path', hash: '#any' }) It still doesn't work; the |
@josh-collinsworth It seems to be working fine for me: https://stackblitz.com/edit/github-n3gkty. Note that if you are using object syntax then you use |
Is there a way we can get this working without hard coded solutions? I have an app where we're passing whatever link is defined in the CMS to nuxt-link. |
Still no updates on this without using workarounds? I'm no leaning towards just using an
|
I think that might be fixed by this PR: Isn't it? |
Waiting for this to be sorted out 😅 |
saaame 👀 |
Is this ever going to be fixed? 🤔 |
Appears to be working fine now, after vue-router bug was fixed. I've taken the initial codesanbox example, exported it, updated Nuxt to 2.16.3, ran |
Closing here then 👍🏻 |
Version
v2.5.1
Reproduction link
https://codesandbox.io/s/mz4wjpzy18
Steps to reproduce
What is expected ?
working anchors accessible from any page (same or different)
What is actually happening?
no navigation is perfomed
Additionnal comment
default
scrollBehavior
does not allow to reach anchors on the same page, but overriding it partially fixes the issue.The text was updated successfully, but these errors were encountered: