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

onBeforeRouteLeave is called twice in some cases #1344

Closed
sqal opened this issue Mar 16, 2022 · 2 comments
Closed

onBeforeRouteLeave is called twice in some cases #1344

sqal opened this issue Mar 16, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@sqal
Copy link

sqal commented Mar 16, 2022

Version

4.0.14

Reproduction link

https://github.com/sqal/vue-rotuer-bug

It's vite app so npm install && npm run dev

Steps to reproduce

  1. Click Log in button
  2. Navigate to /item/edit/1
  3. Click on Go to /home link or click on the back button inyour browser - at this point onBeforeRouteLeave callback is called only once what you can see in the console logs

steps to reproduce bug:

  • Open main.js and uncomment this part:
let be = router.beforeEach((to, from, next) => {
  console.log('beforeEach');
  next(false);
});

Log out from the app, refresh page, and again follow steps 1-3. Now you should see the bug where onBeforeRouteLeave is called twice and it only occurs when you click on the back button in your browser. if you click on Router link it's only called once.

What is expected?

onBeforeRouteLeave to be called only once

@sqal sqal changed the title onBeforeRouteLeave is called twice when in some cases onBeforeRouteLeave is called twice in some cases Mar 16, 2022
@posva posva closed this as completed in faa8562 Mar 16, 2022
@posva posva added the bug Something isn't working label Mar 16, 2022
@ivos
Copy link

ivos commented Apr 21, 2023

I too see onBeforeRouteLeave called twice, even in 4.1.6 version.

Might be a regression of this issue, but frankly it's hard to tell, as the repo in the repro link above is not available anymore and there were exactly zero tests written as part of the faa8562 commit that tried to fix it.

I might create repro when I have a free couple of hours, but in the meantime I would like to humbly propose the advantages of starting every fix by writing a failing test. Creating a repro for a router is not exactly easy, you need a full-blown front-end project for that. All the more reason for strong test coverge.

@sqal
Copy link
Author

sqal commented Apr 21, 2023

@ivos I am sorry for deleting my original repository. I have restored it. As for the bug itself, I no longer see it in vue-router 4.1.6. Maybe yours is different from mine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants