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

beforeRouteUpdate not work when different routes route to same Component #444

Closed
clouds56 opened this issue Aug 25, 2020 · 3 comments · Fixed by #446
Closed

beforeRouteUpdate not work when different routes route to same Component #444

clouds56 opened this issue Aug 25, 2020 · 3 comments · Fixed by #446
Labels
bug Something isn't working has workaround A workaround has been found to deal with the issue

Comments

@clouds56
Copy link

Version

4.0.0-beta.7

Reproduction link

https://codesandbox.io/s/vue-router-next-beforerouteupdate-qpclb

Steps to reproduce

  • Have different routes points to the same Component
  • Register beforeRouteLeave, beforeRouteEnter and beforeRouteUpdate
  • Switch between router-link, you would not receive all navigation event

What is expected?

  1. Click on 1, shows "leave /app/1" and "enter /app/1"
  2. Click on 2, shows "update /app/2"
  3. Click on Home, shows "leave /" and "enter /"

What is actually happening?

  1. Click on 1, shows "leave /app/1" and "enter /app/1"
  2. Click on 2, nothing shows
  3. Click on Home, shows "enter /"
@clouds56
Copy link
Author

When you have routes like this

routes: [
  { path: '/', component: Foo },
  { path: '/app/:matchAll(.*)', component: Foo },
],

and Component Foo registers beforeRouteLeave, beforeRouteEnter and beforeRouteUpdate like this

beforeRouteUpdate(to, from, next) {
  console.log('update', to.path)
  next()
},
  • navigate to / (tigger enter)
  • then /app/1 (tigger leave and enter)
  • then /app/2 (should trigger update but not)
  • then / (should tigger leave but not)

@posva posva added the bug Something isn't working label Aug 25, 2020
posva added a commit that referenced this issue Aug 26, 2020
@posva posva added the has workaround A workaround has been found to deal with the issue label Aug 27, 2020
@posva
Copy link
Member

posva commented Aug 27, 2020

I forgot to say a workaround is to key the router-view:

<router-view :key="$route.path" />

posva added a commit that referenced this issue Sep 1, 2020
@posva posva closed this as completed in #446 Sep 1, 2020
@anncwb
Copy link

anncwb commented Oct 27, 2020

@posva <router-view :key="$route.path" /> This seems to make keepAlive invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has workaround A workaround has been found to deal with the issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants