-
Notifications
You must be signed in to change notification settings - Fork 0
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
RFC: usePreventNavigate
#15
Comments
usePreventNavigate((url?: URL) => boolean | Promise<boolean>)
usePreventNavigate
So that I understand correctly, if the user was to navigate to this form page, and then fill out a form, let's say they hit the browser I sometimes do this on accident and see that the browser sometimes prevents me from going back to the previous URL and I'm relieved. I wonder at what point this would be a frustrating experience. |
@thejackshelton yes correct. I hope it's not a frustrating experience when the navigation is only prevented when there are changes. By making it a hook, it can get at all the metadata it needs to make that decision. |
This is terrific functionality, and a common need in web apps when the page is in a dirty state. The UX way to avoid frustration is to ensure there is either:
These wouldn't need to be enforced in any way, but could be mentioned in documentation as best practices. |
thanks @AnthonyPAlicea ! Now that it's merged and will soon be released as "experimental" we would love a docs PR with your expertise sprinkled all over it 🙏🙌 |
Proposed in #14
Champion
@wmertens
Summary:
usePreventNavigate((url?: URL) => boolean | Promise<boolean>)
What's the motivation for this proposal?
Problems you are trying to solve:
Goals you are trying to achieve:
Proposed Solution / Feature
What do you propose?
We add
usePreventNavigate(cb)
, which registers a handler that will be called when there is a navigation event. When the handler returnstrue
, navigation is blocked.This is actually not trivial to implement correctly because not all navigation passes through qwik-city, and when the browser is involved the answer need to be synchronous.
If the navigation attempt is going through qwik-city, the callback will receive the URL of the desired target. This makes it possible to perform the navigation later.
Code examples
using a modal library:
Using a separate modal:
PRs/ Links / References
PRs:
QwikDev/qwik#6825
Reference:
Remix Router has
useBlocker
, there are interesting tidbits in their decisions document.The text was updated successfully, but these errors were encountered: