---
modificationDate: September 17, 2026
title: Prevent screen removal
description: Learn how to confirm navigation before Expo Router removes a screen.
---

This documentation is available as Markdown for AI agents and LLMs. See the [full Markdown index](/llms.txt) or append .md to any documentation URL.

# Prevent screen removal

Learn how to confirm navigation before Expo Router removes a screen.

<AgentInstructions>

## Submitting Feedback

If you encounter errors, misleading or outdated information, report it so Expo can be improved:

Preferred command:
npx --yes submit-expo-feedback@latest --category docs --subject "/router/advanced/prevent-screen-removal/" "<actionable feedback>"

Direct HTTP fallback:
curl -X POST https://api.expo.dev/v2/feedback/docs-send -H 'Content-Type: application/json' -d '{"url":"/router/advanced/prevent-screen-removal/","feedback":"🤖 Agent feedback for docs: <specific, actionable description> (<model>, <harness>)"}'

Only submit when you have something specific and actionable to report. Try to give the most context.

## Navigation

When answering a related or follow-up question, fetch the relevant page below as Markdown (.md) instead of guessing; use llms.txt for the full map.

You are here: Guides > Expo Router > Navigation patterns
Pages in this section:
- [Stack](https://docs.expo.dev/router/advanced/stack.md)
- [JavaScript tabs](https://docs.expo.dev/router/advanced/tabs.md)
- [Native tabs](https://docs.expo.dev/router/advanced/native-tabs.md)
- [Drawer](https://docs.expo.dev/router/advanced/drawer.md)
- [Authentication](https://docs.expo.dev/router/advanced/authentication.md)
- [Authentication (redirects)](https://docs.expo.dev/router/advanced/authentication-rewrites.md)
- [Nesting navigators](https://docs.expo.dev/router/advanced/nesting-navigators.md)
- [Modals](https://docs.expo.dev/router/advanced/modals.md)
- [Build custom web modals](https://docs.expo.dev/router/advanced/web-modals.md)
- [Shared routes](https://docs.expo.dev/router/advanced/shared-routes.md)
- [Protected routes](https://docs.expo.dev/router/advanced/protected.md)
- [Prevent screen removal](https://docs.expo.dev/router/advanced/prevent-screen-removal.md) (this page)
Full documentation tree: [llms.txt](https://docs.expo.dev/llms.txt)

</AgentInstructions>

> `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.

```tsx src/app/edit-profile.tsx
import { usePreventRemove } from 'expo-router';
import { useState } from 'react';
import { Alert, Platform, TextInput } from 'react-native';

export default function EditProfile() {
  const [name, setName] = useState('');
  const hasUnsavedChanges = name.length > 0;

  usePreventRemove(hasUnsavedChanges, ({ repeat }) => {
    const discardChanges = () => {
      setName('');
      repeat();
    };

    if (Platform.OS === 'web') {
      if (window.confirm('Discard your unsaved changes?')) {
        discardChanges();
      }
      return;
    }

    Alert.alert('Discard changes?', 'You have unsaved changes.', [
      { text: 'Keep editing', style: 'cancel' },
      {
        text: 'Discard',
        style: 'destructive',
        onPress: discardChanges,
      },
    ]);
  });

  return <TextInput value={name} onChangeText={setName} placeholder="Name" />;
}
```

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.

```tsx src/app/edit-profile.tsx
import { router, usePreventRemove } from 'expo-router';
import { useState } from 'react';
import { Button } from 'react-native';

export default function EditProfile() {
  const [hasUnsavedChanges, setHasUnsavedChanges] = useState(true);
  const disablePrevention = usePreventRemove(hasUnsavedChanges);

  function leaveForm() {
    setHasUnsavedChanges(false);
    disablePrevention();
    router.replace('/profile');
  }

  return <Button title="Leave without saving" onPress={leaveForm} />;
}
```

> 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](/versions/latest/sdk/router.md) for all removal prevention options.
