This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Prevent screen removal
Edit page
Learn how to confirm navigation before Expo Router removes a screen.
usePreventRemove()is available in Expo SDK 58 and later.
Use usePreventRemove() to keep a screen open while it contains unsaved changes. The hook runs your callback when navigation tries to remove the screen.
Set the value passed to usePreventRemove() to false before calling repeat(). This keeps your state synchronized with removal prevention.
Disable removal prevention
The hook also returns a function that disables prevention. Use it when you want to cancel the blocked action and navigate somewhere else.
On web,
usePreventRemove()also requests browser confirmation before a refresh, closing the tab, or external navigation. The browser controls whether a dialog appears and its message.
See the Expo Router API reference for all removal prevention options.