A tab often needs more than one screen: an orders tab opens an order, a settings tab opens its sub-pages. A stack nested in the tab gives it pushed screens while the tab bar stays visible, and with native tabs it is also how the tab gets a header. Once a tab holds a stack, you also decide what a tap on the tab you are already on does, and what happens to the screens the stack keeps below the visible one.

Key terms

  • disablePopToTop: a NativeTabs.Trigger prop that stops a tap on the active tab from returning its stack to the root screen.
  • activityEnabled: a navigator and screen option, false by default, that hides inactive route content with React's <Activity> while keeping its state.
  • freezeOnBlur: the option activityEnabled replaces, which is deprecated and has no effect in Expo Router.

One layout route per navigator

In Expo Router a layout route defines each navigator, and nesting renders one navigator inside a screen of another. To give a tab its own stack, make the tab a folder whose _layout.tsx returns a Stack, and give the tab's trigger the folder name:

text
src/app/(tabs)/_layout.tsx
src/app/(tabs)/index.tsx
src/app/(tabs)/orders/_layout.tsx
src/app/(tabs)/orders/index.tsx
src/app/(tabs)/orders/[id].tsx
src/app/(tabs)/orders/track.tsx

A Link inside the orders tab pushes [id] or track onto that tab's stack, and the tab bar stays visible.

Who draws the header depends on the tabs you use. Native tabs have no header, so the nested Stack is what gives the orders tab a header. JavaScript Tabs draw a header of their own, and each navigator adds its own header, so with JavaScript tabs set headerShown: false in the tabs layout's screenOptions and let the stack draw it.

The shop example below has two files: the native tabs layout, and OrdersLayout in orders/_layout.tsx. The trigger <NativeTabs.Trigger name="orders" disablePopToTop> matches the orders folder.

Tapping the tab you are already on

With native tabs, tapping the active tab closes every screen in its stack and returns to the root screen. This dismiss behavior works on Android since SDK 55. When the tab already shows its root screen, the same tap scrolls the content back to the top. Two trigger props turn these off: disablePopToTop and disableScrollToTop.

The orders tab sets disablePopToTop because a user tracking a parcel who taps Orders again by mistake would otherwise lose the tracking screen.

JavaScript tabs get this from Expo Router's own listener instead: a stack nested in a JavaScript tab pops to its first screen when the user presses that tab while it is focused and the stack holds more than one screen, unless the tabPress event was prevented. Leaving the tab doesn't pop the stack unless you set popToTopOnBlur: true on it (the default is false).

Hiding covered screens with activityEnabled

freezeOnBlur has no effect in SDK 58, in stack options and in JavaScript tabs options alike. Its replacement is activityEnabled, an experimental option added in SDK 58 that uses React's <Activity> on route content. Hidden content runs its effect cleanups and releases resources, but keeps its React state until it is visible again.

The option is off by default, and what makes a screen hide depends on the navigator:

  • A Stack hides a screen once two screens sit above it. The count is the focused screen's index minus the screen's own index, so the focused screen and the one right below it stay visible.
  • A positive number on a stack sets that threshold instead, and 1 hides a screen as soon as it loses focus. A number that isn't positive warns in development and turns Activity off.
  • JavaScript tabs, native tabs, headless tabs and drawers hide a screen as soon as it loses focus, and take only a boolean.

In OrdersLayout, <Stack activityEnabled> uses the stack's default threshold of two. When the user goes from index to [id] to track, index has two screens above it and hides, while [id] has one and stays visible. A Stack.Screen in the layout can override the navigator with its own boolean or number.

Nested navigators hide together. When a route that holds a nested navigator hides, all screens of that navigator hide too. The tabs layout sets <NativeTabs activityEnabled>, so opening the Shop tab hides the orders tab and every screen of its stack, while the OrdersLayout component itself keeps running its effects. A NativeTabs.Trigger declared in the layout can override the value it inherits from NativeTabs, and activityEnabled={false} on a nested navigator or screen keeps it active, the way a podcast tab keeps playing while the user browses another tab.

Code Examples

tsx
// src/app/(tabs)/_layout.tsx
import { NativeTabs } from 'expo-router/native-tabs';

export default function TabLayout() {
  return (
    <NativeTabs activityEnabled>
      <NativeTabs.Trigger name="index">
        <NativeTabs.Trigger.Label>Shop</NativeTabs.Trigger.Label>
        <NativeTabs.Trigger.Icon sf="house.fill" md="home" />
      </NativeTabs.Trigger>
      <NativeTabs.Trigger name="orders" disablePopToTop>
        <NativeTabs.Trigger.Label>Orders</NativeTabs.Trigger.Label>
      </NativeTabs.Trigger>
    </NativeTabs>
  );
}
tsx
// src/app/(tabs)/orders/_layout.tsx
import { Stack } from 'expo-router';

export default function OrdersLayout() {
  return (
    <Stack activityEnabled>
      <Stack.Screen name="index" options={{ title: 'Orders' }} />
      <Stack.Screen name="[id]" options={{ title: 'Order details' }} />
      <Stack.Screen name="track" options={{ title: 'Track parcel' }} />
    </Stack>
  );
}
✓ Completed