-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Ability to intercept a navigation request #2974
Comments
Closing this since there is an issue for that already #560 |
Reopening this since it is a different request from the |
Will this work for you? https://github.com/sw-yx/svelte-actions#preventtabclose |
@IsaacHub No, I also need to handle browser buttons, hrefs, and programmatically navigation without a button. I've already made a pull request for that here: #2982 |
Describe the problem
I was trying to build a confirmation dialog feature that appears before the user tries to leave the page.
The problem that occurred is that normally in this case we would use
beforeunload
listener and prevent the navigation event from firing before leaving the page. However, in sveltekit we have client-side routing so this event is not fired.Currently, there is no good way of handling that.
Describe the proposed solution
My proposed solution is to create a listener that exposes the navigation intent.
Within this intent, we should be able to cancel the navigation and get the required information about the page we are trying to navigate to.
The idea is to create a
onBeforeNavigate
interceptor that is triggered when we use the following events:The interceptor could be used in the following way:
Alternatives considered
An alternative is just to disable the client-side router
Importance
i cannot use SvelteKit without it
Additional Information
No response
The text was updated successfully, but these errors were encountered: