-
-
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
Ability to prevent scrollBehavior
on a particular <router-link>
#2921
Comments
I think adding a custom scrollBehavior(to, from, savedPosition) {
if (to.meta.noScroll) return
// rest of the code
} It's not added to typings though, so I will add that, but we can return I don't think adding more props to router-link is the way to go here. This is one of the use cases for |
@posva would it be possible to reconsider something along these lines? I have a couple of use cases where it would be good to have control over scrollBehavior for individual navigations (rather than at the route level through the meta parameter as you suggest). I think an ideal solution would be to pass an object that would override the output of the scrollBehaviour function of the router, e.g. First use case: Changing hash in the url as user scrolls Second use case: Scrolling to the top of a table on pagination My current workaround is to have a scrollBehavior object in my state which I set on particular navigation events and then read that in the scrollBehavior function. Being able to set it directly in the navagation would be much simpler and provide a lot more flexibility with scrolling. |
@jdnz this is a pain I agree. "route level" doesnt work for me. the hacky way i did it is adding ns=1 to the URL using the query string and then ignoring scroll if thats there. That way I can do it at the router-link level.
|
What problem does this feature solve?
In some situations, when one is just changing the
hash
(orquery
) the current page scrolls to top (or not quite to the right position). It would be nice to disable thescrollBehavior
when users click on a specific<router-link>
.Use case: when controlling tabbed content on a page, clicking the link should change the URL, but the user browser view shouldn't be scrolled (as the tabbed content just updates, and the user should remain at their current scroll position).
I know this is possible with a custom
scrollBehaviour()
method, but it tends to make the app maintenance a bit more complex when adding new tabbed content sections in a document.What does the proposed API look like?
Possibly a new Boolean prop
prevent-scroll
on<router-link>
, which when set would disable thescrollBehavior
when users click on the<router-link>
(specifically for when only the hash or query changes), or an optional property in the location object passed to<router-link>
.The text was updated successfully, but these errors were encountered: