A modal presents a screen on top of the one the user is on. Expo Router can present any route in a stack this way, and React Native's own Modal component covers the cases that don't belong in navigation. Picking the wrong one either gives a throwaway dialog a URL it doesn't need or leaves a real flow without one. Each platform also draws and closes a modal in its own way, and on the web you build the close control yourself.
Key terms
- presentation: the stack screen option that sets how a screen appears when it opens, such as
'card','modal'or'formSheet'. - Modal: the React Native core component that overlays content on the current screen without being part of navigation.
- transparentModal: a
presentationvalue that keeps the previous screen visible below a screen with a translucent background. - fullScreenModal: a
presentationvalue that covers the whole screen on iOS and falls back to'modal'on Android. - useCanGoBack: an Expo Router hook that returns the same boolean as
router.canGoBack()and re-renders the component when it changes.
Route or component
Modal belongs to React Native's core API, not to Expo Router. It fits self-contained tasks that don't need to be part of navigation, and temporary alerts or confirmation dialogs. A "Delete this expense?" prompt with two buttons is a good match: nobody needs to link to it, and it has no place in the back history.
A modal route is a file in src/app that becomes a screen in the existing stack. Use one for interactions that are part of navigation, such as a multi-step form you can link into. Because it is a route, it has a URL, so a Link or a deep link can open it. Adding an expense with an amount, a category and a receipt photo is that kind of flow.
presentation: 'modal' on a Stack.Screen
To present a route as a modal, declare it with Stack.Screen in the stack's layout and set presentation: 'modal' in its options. The ExpensesLayout example does this for add-expense, next to the index list. Nothing changes on the opening side: <Link href="/add-expense">Add expense</Link> on the list screen opens it like any other route.
When a screen sets no presentation at all, Expo Router uses 'card', the regular push, unless a modal is already showing below it.
How each presentation value looks
presentation accepts the stack presentation values of react-native-screens, with 'card' in place of 'push':
'card'pushes the screen onto the stack. It slides in from the side on iOS, and on Android the animation depends on the OS version and theme.'modal'presents the screen modally and allows a nested stack inside it. The screen below is unmounted as soon as the transition ends.'transparentModal'also presents modally, but the previous screen stays, so content below shows through a translucent background.'containedModal'and'containedTransparentModal'use iOS current-context modal styles, and fall back to'modal'and'transparentModal'on Android.'fullScreenModal'uses the full-screen modal style on iOS and falls back to'modal'on Android, so the full-screen look is iOS behavior.'formSheet'presents a bottom sheet that rests at chosen heights, covered in the next lesson.
Closing a modal on each platform
On Android, a modal slides on top of the current screen, and the back button dismisses it. On iOS, it slides up from the bottom, and the user closes it by swiping down from the top. gestureEnabled decides whether that swipe works. It defaults to true and is supported only on iOS, so setting it to false on the expense form stops a stray swipe from closing it.
On the web, a modal is shown as a separate route, and you have to provide the dismiss control. router.canGoBack() tells you whether the modal was presented over another screen. After a reload, or when the user opened the URL directly, nothing sits below it, and the modal should be laid out as a full screen.
router.canGoBack() is a plain function call, and it returns false while the navigation container hasn't mounted yet. To use the answer while rendering, call useCanGoBack() instead. It returns the same value and re-renders the component when that value changes, which can happen once after the first render when tabs or a drawer are involved. The AddExpenseScreen example stores it in isPresented and renders {isPresented && <Link href="../">Cancel</Link>}, so the cancel link appears only when a screen sits below the modal. On the web, href="../" navigates to the root route, which here is the expense list. That is a navigation to a route, and it doesn't work like going back.
Screens opened from inside a modal
If a screen pushed while a modal is showing sets no presentation, Expo Router shows it as a modal too, because a modal screen is below it, and in development it warns that this may change in a future version. If it sets presentation: 'card' explicitly, iOS pushes it behind the modal, where it stays hidden until the modal closes. Expo Router warns about that as well, and its message gives the two fixes: use a modal presentation for that route, or close the modal before you navigate.
Code Examples
import { Stack } from 'expo-router';
export default function ExpensesLayout() {
return (
<Stack>
<Stack.Screen name="index" options={{ title: 'Expenses' }} />
<Stack.Screen name="add-expense" options={{ presentation: 'modal' }} />
</Stack>
);
}import { Link, useCanGoBack } from 'expo-router';
import { StyleSheet, Text, View } from 'react-native';
export default function AddExpenseScreen() {
const isPresented = useCanGoBack();
return (
<View style={styles.screen}>
<Text style={styles.title}>Add expense</Text>
{/* On the web, a modal needs its own dismiss control */}
{isPresented && <Link href="../">Cancel</Link>}
</View>
);
}
const styles = StyleSheet.create({
screen: { flex: 1, padding: 16, gap: 12 },
title: { fontSize: 20, fontWeight: '600' },
});