This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
防止屏幕移除
编辑页面
了解如何在 Expo Router 移除屏幕前确认导航
重要
usePreventRemove()在 Expo SDK 58 及更高版本中可用
当屏幕包含未保存的更改时,使用 usePreventRemove() 保持屏幕打开。当导航尝试移除屏幕时,该 Hook 会运行你的回调。
src/app/edit-profile.tsx
在调用 repeat() 前,将传递给 usePreventRemove() 的值设置为 false。这样可以使你的状态与移除防止保持同步。
禁用移除防止
该 Hook 还会返回一个禁用防止功能的函数。当你想要取消被阻止的操作并导航到其他位置时,可以使用它。
src/app/edit-profile.tsx
信息 在 Web 上,
usePreventRemove()还会在刷新、关闭标签页或进行外部导航之前请求浏览器确认。是否显示对话框及其消息由浏览器控制
有关所有移除防止选项,请参阅 Expo Router API 参考。