-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[v6] useBlocker prevents navigation outside app #7782
Comments
Hello, The key is to use the hook useBlocker outside the main logic component you can find an example here : Regards; |
Bump, I believe I have a similar issue. I use However, I am actually most specifically interested in the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The intent of You could definitely argue that it's not the job of the history library to block document reloads since you already have the ability to hook into |
Closing since this API is no longer in the library. #8139 will track when it's added back. |
I have a React-Router v6 based app. I created a component that, if mounted, prevents the user from using "Back" button. If they decide to proceed anyway, it redirects the user to the home page instead.
This works perfectly, with one small gotcha: when the user clicks an external link, a prompt asking for confirmation appears. This is unintended.
I investigated a little bit, and it appears that whenever useBlocker is present (and active) on the page,
history
package adds onBeforeUnload listener, causing said unwanted prompt.The only solution I could come up with was to listen for events on links that are about to be clicked and disable useBlocker right before they are actually clicked, but this seems hacky as hell.
Is there any better way to do this?
The text was updated successfully, but these errors were encountered: