-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Idea: Hook to prevent navigation #105
Comments
Hey @silverwind thanks for a suggestion! Something similar has already been asked, I've even put together a small demo that illustrates this principle with wouter here #39 I should however add the Promise support to the demo and place the link to the demo in the readme (we have a special section called Code Recipes for things that are requested but seem a bit out of scope of the library). Now the question is whether there should be a first-class support for this feature in wouter. IMO the feature sounds really independent from the routing and only operates with location hook, so I would keep it out of the main bundle. Perhaps, we could release something like |
Thanks for the example. I will try to implement it like that. Would have preferred to do it without Context, but I guess it's the only way currently. It's certainly only a feature very few users will need. Maybe |
I've implemented your example. One issue I ran into was that a import of https://codesandbox.io/s/wouter-interruptible-transition-ojbkv |
Closing in favor of #112. |
A feature like <Prompt> would be nice to have to prevent navigation based on the outcome of a user-defined condition, for example when a user clicks a
<Link>
while a unsaved form is present on the page.I could see a new hook
usePreventNavigation
to be used for it. It should accept a function that returns either asynchronous result or a Promise for a result. If the result istrue
, any navigation attempts in the current component or its children should be prevented.The text was updated successfully, but these errors were encountered: