-
-
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
Allow router.replace without triggering scrollBehavior #2072
Comments
I'd rather keep it in #1620 |
hm, can i just add meta to the route and read from that? |
yep, but it will be linked to the route, not the navigation. I don't see why you would need to skip navigation guards in a navigation, it could make things fail easily 🤔 |
Hm, it appears i have to define meta for every route... this feature spans multiple routes. This is what I'm attempting:
Any ideas? |
I only use the query parameters for saving data that you might want when you share a link or reload the page. For example where you are in a list |
You can add the meta in the route definition as well so it is always applied, but yeah, you have to define where to use it 🙂 |
Yeah but I can't have it always apply, what I need is to be able to see the difference between a query parameter update and a navigation (push) to the page. It appears meta is only per route, and never per route object (ie per entry in router.routes, not per router.route object) |
that's |
It's not the same because going from /product/1 to /product/2 through a push will still go through beforeRouteUpdate, while I want to prevent some behaviour when going from /product/1 to /product/1?image=2 |
If anyone has similar problems and finds this issue, I solved it by not scrolling if the only thing that changed was the query/hash:
isEqual is a lodash function that makes a deep comparison of the two objects |
Similar, but without requiring lodash:
|
What problem does this feature solve?
Using router.replace to update query parameters. However this triggers scrollBehavior and scrolls to the top. As far as I know, there is no way to distinguish between a push and a replace event.
What does the proposed API look like?
Here are some options:
Could be a simple boolean passed to the scrollBehavior function
It could be put in the route object to be consistent with this suggestion: #1620
I could also work with the replace function accepting an additional parameter, or having a new signature, that simply updates the url and
router.$route
without going through guards, scrollbehavior etc. I originally just updated the state manually to circumvent this (using history.replaceState), however that caused some other sneaky bugs since vue-router didn't know about these changes.The text was updated successfully, but these errors were encountered: