Expo Router UI

GitHub

npm

An Expo Router submodule that provides headless UI navigators to create custom layouts.

Android
iOS
Web

expo-router/ui is a submodule of expo-router library and exports components and hooks to build custom layouts, rather than using the default React Navigation navigators provided by expo-router.

See the Expo Router reference for more information about the file-based routing library for native and web app.

Installation

Terminal
- npx expo install expo-router

Configuration in app config

If you are using the default template to create a new project, expo-router config plugin is automatically configured in the app config automatically.

Example app.json with config plugin

app.json
{
  "expo": {
    "plugins": ["expo-router"]
  }
}

Usage

Find more information about using expo-router/ui in Expo Router UI guide.

API

import { Tabs, TabList, TabTrigger, TabSlot } from 'expo-router/ui';

Components

defaultTabsSlotRender

Type: React.Element<Descriptor<ExpoTabsNavigatorScreenOptions, Omit<undefined & PrivateValueStore<[ParamListBase, unknown, unknown]>, 'getParent'> & undefined & EventConsumer<TabNavigationEventMap & EventMapCore<TabNavigationState<any>>> & PrivateValueStore<[ParamListBase, string, TabNavigationEventMap]> & TabActionHelpers<ParamListBase>, RouteProp<ParamListBase, string>>>

TabList

Type: React.Element<TabListProps>

Wrapper component for TabTriggers. TabTriggers within the TabList define the tabs.

Example

<Tabs>
 <TabSlot />
 <TabList>
  <TabTrigger name="home" href="/" />
 </TabList>
</Tabs>
Android
iOS
Web

asChild

Optional • Type: boolean

Forward props to child component and removes the extra <View>. Useful for custom wrappers.

Inherited Props

Tabs

Type: React.Element<TabsProps>

Root component for the headless tabs.

See: useTabsWithChildren for a hook version of this component.

Example

<Tabs>
 <TabSlot />
 <TabList>
  <TabTrigger name="home" href="/" />
 </TabList>
</Tabs>
Android
iOS
Web

asChild

Optional • Type: boolean

Forward props to child component and removes the extra <View>. Useful for custom wrappers.

Android
iOS
Web

options

Optional • Type: UseTabsOptions

Inherited Props

TabSlot

Type: React.Element<UseTabSlotOptions>

Renders the current tab.

See: useTabSlot for a hook version of this component.

Example

<Tabs>
 <TabSlot />
 <TabList>
  <TabTrigger name="home" href="/" />
 </TabList>
</Tabs>

TabTrigger

Type: React.Element<TabTriggerProps>

Creates a trigger to navigate to a tab. When used as child of TabList, its functionality slightly changes since the href prop is required, and the trigger also defines what routes are present in the Tabs.

When used outside of TabList, this component no longer requires an href.

Example

<Tabs>
 <TabSlot />
 <TabList>
  <TabTrigger name="home" href="/" />
 </TabList>
</Tabs>
Android
iOS
Web

asChild

Optional • Type: boolean

Forward props to child component. Useful for custom wrappers.

Android
iOS
Web

href

Optional • Type: Href

Name of tab. Required when used within a TabList.

Android
iOS
Web

name

Type: string

Name of tab. When used within a TabList this sets the name of the tab. Otherwise, this references the name.

Android
iOS
Web

reset

Optional • Type: SwitchToOptions['reset'] | 'onLongPress'

Resets the route when switching to a tab.

Inherited Props

useTabSlot

Type: React.Element<UseTabSlotOptions>

Returns a ReactElement of the current tab.

Example

function MyTabSlot() {
  const slot = useTabSlot();

  return slot;
}

Constants

Hooks

Android
iOS
Web

useTabSlot(options)

ParameterType
options
(optional)
UseTabSlotOptions

Returns a ReactElement of the current tab.

Returns:

Element

Example

function MyTabSlot() {
  const slot = useTabSlot();

  return slot;
}
Android
iOS
Web

useTabsWithChildren(options)

ParameterType
optionsUseTabsWithChildrenOptions

Hook version of Tabs. The returned NavigationContent component should be rendered.

See: Tabs for the component version of this hook.

Example

export function MyTabs({ children }) {
 const { NavigationContent } = useTabsWithChildren({ children })

 return <NavigationContent />
}
Android
iOS
Web

useTabsWithTriggers(options)

ParameterType
optionsUseTabsWithTriggersOptions

Alternative hook version of Tabs that uses explicit triggers instead of children.

See: Tabs for the component version of this hook.

Example

export function MyTabs({ children }) {
  const { NavigationContent } = useTabsWithChildren({ triggers: [] })

  return <NavigationContent />
}
Android
iOS
Web

useTabTrigger(options)

ParameterType
optionsTabTriggerProps

Utility hook creating custom TabTrigger.

Types

Android
iOS
Web

ExpoTabsNavigatorOptions

Literal Type: multiple types

Acceptable values are: DefaultNavigatorOptions<ParamListBase, string | undefined, TabNavigationState<ParamListBase>, ExpoTabsScreenOptions, TabNavigationEventMap, ExpoTabsNavigationProp<ParamListBase>> | Omit<TabRouterOptions, 'initialRouteName'> | ExpoTabsNavigatorScreenOptions

Android
iOS
Web

ExpoTabsNavigatorScreenOptions

NameTypeDescription
detachInactiveScreens
(optional)
boolean-
freezeOnBlur
(optional)
boolean-
lazy
(optional)
boolean-
unmountOnBlur
(optional)
boolean-
Android
iOS
Web

SwitchToOptions

Options for switchTab function.

NameTypeDescription
reset
(optional)
ExpoTabsResetValue

Navigate and reset the history.

Android
iOS
Web

TabsContextValue

Type: ReturnType<useNavigationBuilder>

The React Navigation custom navigator.

See: useNavigationBuilder hook from React Navigation for more information.

Android
iOS
Web

TabsSlotRenderOptions

Options provided to the UseTabSlotOptions.

NameTypeDescription
detachInactiveScreensboolean

Should the screen be unloaded when inactive.

indexnumber

Index of screen.

isFocusedboolean

Whether the screen is focused.

loadedboolean

Whether the screen has been loaded.

Android
iOS
Web

TabTriggerOptions

NameTypeDescription
hrefHref-
namestring-
Android
iOS
Web

Trigger

Type: extended by:


NameTypeDescription
isFocusedboolean-
resolvedHrefstring-
routeundefined[number]-
Android
iOS
Web

UseTabSlotOptions

Type: ComponentProps<ScreenContainer> extended by:


NameTypeDescription
detachInactiveScreens
(optional)
boolean

Remove inactive screens.

renderFn
(optional)
defaultTabsSlotRender

Override how the Screen component is rendered.

Android
iOS
Web

UseTabsOptions

Options to provide to the Tab Router.

Type: Omit<DefaultNavigatorOptions<ParamListBase, any, TabNavigationState<any>, ExpoTabsScreenOptions, TabNavigationEventMap, any>, 'children'> extended by:


NameTypeDescription
backBehavior
(optional)
TabRouterOptions['backBehavior']-
Android
iOS
Web

UseTabsWithChildrenOptions

Type: UseTabsOptions extended by:


NameTypeDescription
childrenReactNode-
Android
iOS
Web

UseTabsWithTriggersOptions

Type: UseTabsOptions extended by:


NameTypeDescription
triggersScreenTrigger[]-
Android
iOS
Web

UseTabTriggerResult

NameTypeDescription
getTrigger(name: string) => Trigger | undefined-
switchTab(name: string, options: SwitchToOptions) => void-
trigger
(optional)
Trigger-
triggerPropsTriggerProps-