onBeforeRouteLeave is called twice in some cases
sqal opened this issue · 2 comments
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
- Click Log in button
- Navigate to /item/edit/1
- 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
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.