-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
fix(scrollBehavior): trigger scroll behavior if same route with hash #3592
Conversation
Removing the whole "isSameRoute" condition would also do the trick (as @gspain found out: #1668 (comment)). But I'm concerned that this would have some unwanted side effects that I'm not aware of. |
Because this would have an effect on all the current implementations I could also think of an option for the scroll behavior that developers could set to true—and only then the scroll behavior for same routes would be triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Can you add an e2e test and make sure handleScroll
is only called if there is a hash?
Hi @posva! I guess we misunderstood a little. I've added a test now that checks if clicking the same anchor twice works (scrolls to the anchor location again). But: I haven't added a test that checks if "handleScroll()" is called for URLs with hashes only. I think it's useful to call "handleScroll()" whenever a link is clicked that doesn't change the URL. That will make multiple clicks on the same anchor work out of the box—plus it gives the developer the chance to implement an individual behavior (by customizing the scroll behavior) for clicking a link to the current site again (when there is no hash). They could decide for example to scroll to the top of the page or to reload the entire page (as it happens for simple HTML pages). What do you think? |
It has to be hash only because otherwise this would break existing In Vue Router 4, scrollBehavior already works like you suggested. |
Done! 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Judgement day is here. It's finally fixed!!! |
When can we expect this to be released? |
close #1668
This will make clicks on already active anchor links work.