Expo Router UI

GitHub

npm

An Expo Router submodule that provides headless tab components to create custom tab layouts.

Android
iOS
Web

expo-router/ui is a submodule of expo-router library and exports components and hooks to build custom tab 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

TabList

Android
iOS
Web

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>

TabListProps

asChild

Android
iOS
Web
Optional • Type: boolean

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

Inherited Props

Tabs

Android
iOS
Web

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>

TabsProps

asChild

Android
iOS
Web
Optional • Type: boolean

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

options

Android
iOS
Web
Optional • Type: UseTabsOptions

Inherited Props

TabSlot

Android
iOS
Web

Type: React.Element<TabSlotProps>

Renders the current tab.

See: useTabSlot for a hook version of this component.

Example

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

TabSlotProps

detachInactiveScreens

Android
iOS
Web
Optional • Type: boolean

Remove inactive screens.

renderFn

Android
iOS
Web
Optional • Type: defaultTabsSlotRender

Override how the Screen component is rendered.

Inherited Props

  • ComponentProps<ScreenContainer>

TabTrigger

Android
iOS
Web

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>

TabTriggerProps

asChild

Android
iOS
Web
Optional • Type: boolean

Forward props to child component. Useful for custom wrappers.

href

Android
iOS
Web
Optional • Type: Href

Name of tab. Required when used within a TabList.

name

Android
iOS
Web
Type: string

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

reset

Android
iOS
Web
Optional • Type: SwitchToOptions[reset] | 'onLongPress'

Resets the route when switching to a tab.

useTabSlot

Android
iOS
Web

Type: React.Element<TabSlotProps>

Returns a ReactElement of the current tab.

Example

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

  return slot;
}

Constants

Tabs.TabContext

Android
iOS
Web

Type: Context<ExpoTabsNavigatorScreenOptions>

Hooks

useTabSlot(namedParameters)

Android
iOS
Web
ParameterType
namedParameters(optional)TabSlotProps

Returns a ReactElement of the current tab.

Returns:
Element

Example

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

  return slot;
}

useTabsWithChildren(options)

Android
iOS
Web
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 />
}

useTabsWithTriggers(options)

Android
iOS
Web
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 />
}

useTabTrigger(options)

Android
iOS
Web
ParameterType
optionsTabTriggerProps

Utility hook creating custom TabTrigger.

Types

ExpoTabsNavigatorOptions

Android
iOS
Web

Literal Type: multiple types

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

ExpoTabsNavigatorScreenOptions

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

ExpoTabsResetValue

Android
iOS
Web

Literal Type: string

Acceptable values are: 'always' | 'onFocus' | 'never'

ExpoTabsScreenOptions

Android
iOS
Web

Type: Pick<BottomTabNavigationOptions, 'title' | 'lazy' | 'freezeOnBlur'> extended by:

PropertyTypeDescription
actionNavigationAction-
params(optional)object-
titlestring-

SwitchToOptions

Android
iOS
Web

Options for switchTab function.

PropertyTypeDescription
reset(optional)ExpoTabsResetValue

Navigate and reset the history.

TabNavigationEventMap

Android
iOS
Web
PropertyTypeDescription
tabLongPress{ data: undefined }

Event which fires on long press on the tab in the tab bar.

tabPress{ canPreventDefault: true, data: undefined }

Event which fires on tapping on the tab in the tab bar.

TabsContextValue

Android
iOS
Web

Type: ReturnType<useNavigationBuilder>

The React Navigation custom navigator.

See: useNavigationBuilder hook from React Navigation for more information.

TabsSlotRenderOptions

Android
iOS
Web

Options provided to the UseTabSlotOptions.

PropertyTypeDescription
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.

TabTriggerOptions

Android
iOS
Web
PropertyTypeDescription
hrefHref-
namestring-

Trigger

Android
iOS
Web

Type: extended by:

PropertyTypeDescription
isFocusedboolean-
resolvedHrefstring-
route[number]-

UseTabsOptions

Android
iOS
Web

Options to provide to the Tab Router.

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

PropertyTypeDescription
backBehavior(optional)TabRouterOptions[backBehavior]-

UseTabsWithChildrenOptions

Android
iOS
Web

Type: PropsWithChildren<UseTabsOptions>

UseTabsWithTriggersOptions

Android
iOS
Web

Type: UseTabsOptions extended by:

PropertyTypeDescription
triggersScreenTrigger[]-

UseTabTriggerResult

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