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

Router guards registered with onBeforeRouteLeave are never removed #16

Open
FichteFoll opened this issue Jan 24, 2023 · 1 comment
Open

Comments

@FichteFoll
Copy link

FichteFoll commented Jan 24, 2023

This is on Vue 2.7.

When I add a guard with onBeforeRouteLeave (inside a composable), the specified guard function is registered and called as expected. If I however manage to leave the page (because the guard allowed it) and then enter the same route/component again, a new guard is registered but the previous one is also still active and called. I validated this by printing out calls to the guard, including an auto-generated id of a computed ref that is created within the component.

This is problematic in my case because the guard relies on a computed "canLeave" flag to prompt for user confirmation and that is never updated after the page was left, meaning if the page was left, reentered and then the user wants to leave again, they will always be prompted even if they didn't make any changes on the page they are currently on.

@FichteFoll
Copy link
Author

I worked around this by adding another flag that I set just before I allow leaving the page and that I check as the first thing whenever the guard is called. While it still means the guard is never cleaned up, it does allow the user to leave a page when they should be able to without getting prompted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant