router.back() goes back in the navigation history, following the back handling of whichever navigator has focus. A checkout or an onboarding flow often needs something else: drop the last two steps, return to the start of the flow, or jump back to one known screen. The router's dismiss methods remove screens from the closest stack explicitly, and with nested navigators that stack isn't always the navigator that has focus.

Key terms

  • router.dismiss: removes the last screen of the closest stack, or up to a given number of screens.
  • router.dismissTo: dismisses screens in the current stack until a given Href is reached, and replaces the current screen with it when it isn't in the history.
  • router.dismissAll: dismisses every screen above the first screen of the closest stack.
  • router.canDismiss: returns true when the router is within a stack that has more than one screen in its history.

Removing screens by count

router.dismiss() removes the last screen in the closest stack. It takes an optional positive number and removes up to that many screens, so router.dismiss(2) closes the current step and the one before it. Without an argument the count is 1.

A stack never removes its own first screen this way: a count larger than the history stops at that first screen. If the current screen is the only route in its stack, dismiss dismisses the entire stack, because the stack leaves the action to its parent navigator.

That targeting is the difference from back. dismiss acts on the closest stack instead of the current navigator, so when navigators are nested, one call can take you back several screens.

Returning to a known screen with dismissTo

router.dismissTo() takes an Href, the same type push and replace take, and dismisses screens in the current stack until that href is reached. The stack searches from the current screen downward and stops at the nearest screen for that route.

Take an onboarding stack with the history /welcome, /plan, /profile, where /profile is focused. router.dismissTo('/welcome') removes /profile and /plan and leaves /welcome on screen.

When the href isn't in the history, dismissTo falls back to a replace. Say /finish is a route of the same stack that the user hasn't visited. router.dismissTo('/finish') removes the current /profile screen and puts /finish in its place, keeping every screen below. The history becomes /welcome, /plan, /finish, and nothing is pushed on top of /profile. That fallback applies to routes of the stack itself. A stack doesn't handle a target that isn't one of its own routes.

Back to the first screen with dismissAll

router.dismissAll() dismisses every screen above the first screen in the closest stack and returns to that first screen. It takes no href and no count: whatever the depth, only the first screen remains. That fits a Done or Cancel button at the end of a flow that started from the stack's first screen.

Checking first with canDismiss

router.canDismiss() takes no arguments and returns true when the router is within a stack that has more than one screen in its history. It walks down the focused navigation state from the root and answers true as soon as one stack on that path has more than one screen.

Call it in an event handler or an effect. Called during render, it logs a warning: router.canDismiss() was called during render, which can return a stale value. Use the useCanDismiss() hook to read it during render, or call router.canDismiss() in an effect or event handler. The useCanDismiss() hook, exported from expo-router, returns the same value, re-renders the component when it changes, and is correct during render. Use it when the value decides what to show, such as a Close button that appears only when there is a screen to dismiss.

Calling them from a component

All four methods are on the router that useRouter() returns, next to push, back and the others. In a component, prefer that router over the module-level router: the hook is bound to the Expo Router root that rendered the component, while the module-level router throws if it is called before the first router render.

The ReviewScreen example is the last step of a checkout stack. "Change address" calls router.dismissTo('/checkout/shipping'), which goes back to the shipping step if it is in the history and replaces the review screen with it if it isn't. "Back two steps" calls router.dismiss(2). "Cancel checkout" runs cancelCheckout, which reads router.canDismiss() inside the handler and calls router.dismissAll() only when the stack has a screen to remove.

Code Examples

tsx
// src/app/checkout/review.tsx
import { useRouter } from 'expo-router';
import { Button, View } from 'react-native';

export default function ReviewScreen() {
  const router = useRouter();

  function cancelCheckout() {
    if (router.canDismiss()) {
      router.dismissAll();
    }
  }

  return (
    <View>
      <Button title="Change address" onPress={() => router.dismissTo('/checkout/shipping')} />
      <Button title="Back two steps" onPress={() => router.dismiss(2)} />
      <Button title="Cancel checkout" onPress={cancelCheckout} />
    </View>
  );
}
✓ Completed