Slot: A Layout Without a Navigator

+15 Mana ✨

Some folders don't need a header, a back button or a tab bar. Their pages share a banner, a toolbar or a footer, and the layout's only job is to draw that UI around whichever page is open. Slot from expo-router covers this case, and knowing what it leaves out tells you when a navigator fits better.

Key terms

  • Slot: an expo-router component that a layout renders as a placeholder for the current child route, with no navigator UI of its own.
  • Child route: a route that belongs to a layout, because it sits in the layout's folder or was hoisted up to it from a folder without a layout.

A placeholder for the current page

A layout returns whatever JSX you want around its pages. Put <Slot /> in that JSX and it marks where the current child route goes: Slot renders the currently selected content, and the components around it render on every page of the folder.

Take an account area with three pages:

text
src/app/account/_layout.tsx
src/app/account/index.tsx
src/app/account/orders.tsx
src/app/account/addresses.tsx

AccountLayout returns a fragment with an AccountHeader above the slot and a HelpFooter below it. Slot is imported from expo-router.

At /account, the screen shows AccountHeader, the page from index.tsx, then HelpFooter. Move to /account/orders and the header and footer are drawn around orders.tsx instead. Neither page imports or renders the header itself, so the shared UI lives in one file.

Slot takes no children: the page it shows always comes from the current route, never from JSX you nest inside it, so <Slot><OrdersList /></Slot> is a type error.

What a Slot leaves out

Compared with a navigator, a Slot draws very little. The component that renders its content draws only the focused route and nothing else: no header, no back button, no tab bar and no other screens. A Stack in the same layout would render a header with a back button by default, which pops the current page and returns to the previous one.

Under that bare output, Slot is still a navigator. It is built on a stack router, so its state is a stack of routes, even though only the focused one reaches the screen. A missing back button doesn't mean a missing history.

That bare output is also what an app gets without a root layout. When src/app has no top-level _layout, the default root layout that Expo Router generates is built on Slot.

Picking Slot for a folder

Slot fits a folder whose pages are siblings the user moves between from shared UI: a settings area with a title bar and a menu of sections, or the account pages above, where the header holds links to orders and addresses. The layout draws that UI once, and the slot swaps the page beneath it. A Slot layout is also a place to display a modal over any route of its folder, because whatever the layout renders next to the slot appears on every page.

When the pages in a folder lead into each other and the user expects a back button in a header, return a navigator from the layout instead. A Stack draws that header for you, and the next lesson covers it. A Slot layout can also sit inside a navigator further up the tree: the root layout might return a Stack while account/_layout.tsx returns a Slot, and the account pages then render inside both.

Code Examples

tsx
import { Slot } from 'expo-router';

import { AccountHeader } from '@/components/account-header';
import { HelpFooter } from '@/components/help-footer';

export default function AccountLayout() {
  return (
    <>
      <AccountHeader />
      <Slot />
      <HelpFooter />
    </>
  );
}
✓ Completed