useBlocker on v7 Framework not working
#14776
Unanswered
George-Madeley
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a React Router v7 Framework app (with SSR disabled). I have a react-hook-form Form on a given page. Ideally, I want to block the user from navigating away when any part of the form is dirty. I thought the solution below would be simple enough:
But for some reason, the blocker never blocks. I've also tried
useBeforeUnload()hook and the actualbeforeUnloadwindow event but they also do not work. I understand theuseBlockeris used for internal navigation with<Link />andnavigate()whilstbeforeUnloadif for page reloads, navigate backwards and forwards etc., So surely the solution above should work?This did work on v6 Data Router before migrating to v7 Framework. I thought that the reason would be because
useBlockeris not available on the framework router but the docs just state that the:I thought that by setting
ssr: false,in thereact-router.config.tsfile would solve this as:But this does not seem to be the case.
Has anyone else had any issues with
useBlockerin React Router v7 Framework SPA? If so, how did you resolve the issue?Beta Was this translation helpful? Give feedback.
All reactions