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

v4 breaking change: watchers on $route.query triggered on route change #1381

Closed
taobojlen opened this issue Apr 26, 2022 · 1 comment
Closed

Comments

@taobojlen
Copy link

Version

4.0.14

Reproduction link

codesandbox.io

Steps to reproduce

  1. Create a watcher on $route.query in a component that's only rendered on one route.
  2. Notice that the watcher is triggered when navigating to another route.
  3. If you do the same with Vue 2 / vue-router v3, the watcher is not triggered.

What is expected?

The behaviour is the same as vue-router v3.

What is actually happening?

The behaviour changed!


We have a very common pattern of a watcher on $route.query that fetches data when the URL query changes. Now, because of this change, our app makes many more unnecessary network requests when navigating to different routes.

One potential workaround is to set some global state, like isUnmounting = true, in the router's global before hook (and then unset it in the after hook). Then, we could return early in the watchers if this boolean is true. However, this isn't a very clean solution!

@posva
Copy link
Member

posva commented Apr 26, 2022

Duplicate of vuejs/core#2291 for when leaving a route.

@posva posva closed this as completed Apr 26, 2022
@vuejs vuejs locked and limited conversation to collaborators Jun 8, 2022
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