Skip to content
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

Introduce passive option for router.push/router.replace #2232

Closed
AlttiRi opened this issue May 10, 2024 · 1 comment
Closed

Introduce passive option for router.push/router.replace #2232

AlttiRi opened this issue May 10, 2024 · 1 comment

Comments

@AlttiRi
Copy link

AlttiRi commented May 10, 2024

What problem is this solving

I want to update the location URL without triggering scrollBehavior.

I need to trigger scrollBehavior only on the page refresh, or when I go to the route from other one to scroll the page to the selected item. (I select an item by a click on it then I add its ID to the location URL).

Proposed solution

Add a passive option for router.push/router.replace to skip scrollBehavior and guards, for example, if there is no transition to another route.

router.replace({ params: { id: item.name }, passive: true });

As you can see in this example, I do not use neither name, or path. I'm still on the same route ("/items/:id?") after using replace. Using of hash (/items#1), or searchParams(/items?id=1) for storing a data on the same route have this issue too.


Or add any way to attach a meta object (for example, {passive: true, foo: "bar"}) to check it in scrollBehavior and guard functions.
A simple if (to.state.passive) { return; } in scrollBehavior will be acceptable option too.

Describe alternatives you've considered

Yeah, I can write a workaround, but I (and not only me) would like to see this simple and expected option from the box.

@posva
Copy link
Member

posva commented May 11, 2024

Please stop opening issues that should be questions. Open discussions explaining what you are trying to do.

Add a passive option for router.push/router.replace to skip scrollBehavior and guards, for example, if there is no transition to another route.

Guards and scrollBehavior() are functions, you can already skip them when needed.

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale May 11, 2024
@vuejs vuejs locked as spam and limited conversation to collaborators May 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants