This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo Router UI
一个 Expo Router 子模块,提供无头选项卡组件,用于创建自定义选项卡布局。
expo-router/ui 是 expo-router 库的一个子模块,导出用于构建自定义标签栏布局的无头组件和 hooks。你可以使用它替代 Expo Router 内置的导航器,例如 JavaScript 标签页和原生标签页。
有关适用于原生和 Web 应用的基于文件的路由库的更多信息,请参阅 Expo Router 参考文档。
安装
要在项目中使用 expo-router/ui,需要在项目中安装 expo-router。请按照 Expo Router 的安装指南进行操作:
了解如何在项目中安装 Expo Router。
在 app config 中配置
如果使用 默认 模板创建新项目,expo-router 的配置插件已在 app config 中配置。
Example app.json with config plugin
用法
有关如何使用 expo-router/ui 的信息,请参阅自定义标签栏布局指南:
API
import { Tabs, TabList, TabTrigger, TabSlot } from 'expo-router/ui';
Components
Type: React.Element<Context<ExpoTabsNavigatorScreenOptions>>
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>
Type: React.Element<TabsProps>
Root component for the headless tabs.
See:
useTabsWithChildrenfor a hook version of this component.
Example
<Tabs> <TabSlot /> <TabList> <TabTrigger name="home" href="/" /> </TabList> </Tabs>
boolean • Default: falseEnables React Activity for tab screens. Inactive tabs are hidden while preserving their state.
booleanForward props to child component and removes the extra <View>. Useful for custom wrappers.
UseTabsOptionsType: React.Element<TabSlotProps>
Renders the current tab.
See:
useTabSlotfor a hook version of this component.
Example
<Tabs> <TabSlot /> <TabList> <TabTrigger name="home" href="/" /> </TabList> </Tabs>
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>
booleanOverrides React Activity behavior inherited from Tabs for this route when used in a
TabList.
booleanForward props to child component. Useful for custom wrappers.
stringName of tab. When used within a TabList this sets the name of the tab.
Otherwise, this references the name.
Type: React.Element<TabSlotProps>
Returns a ReactElement of the current tab.
Example
function MyTabSlot() { const slot = useTabSlot(); return slot; }
Hooks
Returns a ReactElement of the current tab.
ElementExample
function MyTabSlot() { const slot = useTabSlot(); return slot; }
Hook version of Tabs. The returned NavigationContent component
should be rendered. Using the hook requires using the <TabList />
and <TabTrigger /> components exported from Expo Router.
The useTabsWithTriggers() hook can be used for custom components.
{
describe: (route: DescriptorRouteProp<ParamListBase, string>) => Descriptor<ExpoTabsNavigatorScreenOptions, Omit<NavigationHelpersCommon<ParamListBase, TabNavigationState<any>>, 'getParent'> & {
} & NavigationHelpersRoute<ParamListBase, string> & EventConsumer<TabNavigationEventMap & EventMapCore<TabNavigationState<any>>> & PrivateValueStore<[ParamListBase, string, TabNavigationEventMap]> & TabActionHelpers<ParamListBase>, RouteProp<ParamListBase>>,
descriptors: Record<string, Descriptor<ExpoTabsNavigatorScreenOptions, Omit<NavigationHelpersCommon<ParamListBase, TabNavigationState<any>>, 'getParent'> & {
} & NavigationHelpersRoute<ParamListBase, string> & EventConsumer<TabNavigationEventMap & EventMapCore<TabNavigationState<any>>> & PrivateValueStore<[ParamListBase, string, TabNavigationEventMap]> & TabActionHelpers<ParamListBase>, RouteProp<ParamListBase>>>,
navigation: {
} & PrivateValueStore<[ParamListBase, unknown, unknown]> & EventEmitter<TabNavigationEventMap> & NavigationHelpersRoute<ParamListBase, string> & TabActionHelpers<ParamListBase>,
NavigationContent: (__namedParameters: {
children: ReactNode
}) => Element,
state: TabNavigationState<any>
}See:
Tabsfor the component version of this hook.
Example
export function MyTabs({ children }) { const { NavigationContent } = useTabsWithChildren({ children }) return <NavigationContent /> }
Alternative hook version of Tabs that uses explicit triggers
instead of children.
{
describe: (route: DescriptorRouteProp<ParamListBase, string>) => Descriptor<ExpoTabsNavigatorScreenOptions, Omit<NavigationHelpersCommon<ParamListBase, TabNavigationState<any>>, 'getParent'> & {
} & NavigationHelpersRoute<ParamListBase, string> & EventConsumer<TabNavigationEventMap & EventMapCore<TabNavigationState<any>>> & PrivateValueStore<[ParamListBase, string, TabNavigationEventMap]> & TabActionHelpers<ParamListBase>, RouteProp<ParamListBase>>,
descriptors: Record<string, Descriptor<ExpoTabsNavigatorScreenOptions, Omit<NavigationHelpersCommon<ParamListBase, TabNavigationState<any>>, 'getParent'> & {
} & NavigationHelpersRoute<ParamListBase, string> & EventConsumer<TabNavigationEventMap & EventMapCore<TabNavigationState<any>>> & PrivateValueStore<[ParamListBase, string, TabNavigationEventMap]> & TabActionHelpers<ParamListBase>, RouteProp<ParamListBase>>>,
navigation: {
} & PrivateValueStore<[ParamListBase, unknown, unknown]> & EventEmitter<TabNavigationEventMap> & NavigationHelpersRoute<ParamListBase, string> & TabActionHelpers<ParamListBase>,
NavigationContent: (__namedParameters: {
children: ReactNode
}) => Element,
state: TabNavigationState<any>
}See:
Tabsfor the component version of this hook.
Example
export function MyTabs({ children }) { const { NavigationContent } = useTabsWithChildren({ triggers: [] }) return <NavigationContent /> }
Types
Type: NavigationProp<ParamList, RouteName, NavigatorID, TabNavigationState<ParamListBase>, ExpoTabsScreenOptions, TabNavigationEventMap>
Type: Omit<DefaultNavigatorOptions<ParamListBase, string | undefined, TabNavigationState<ParamListBase>, ExpoTabsScreenOptions, TabNavigationEventMap, ExpoTabsNavigationProp<ParamListBase>> & TabRouterOptions & ExpoTabsNavigatorScreenOptions, 'initialRouteName'>
Type: Pick<BottomTabNavigationOptions, 'title' | 'lazy' | 'freezeOnBlur' | 'hidden'> extended by:
Type: ReturnType<useNavigationBuilder>
The result of the tab navigation builder used by Expo Router's custom tabs.
See: Custom tabs for building a tab bar and Custom navigators for navigator integration.
Options to provide to the Tab Router.
Type: Omit<DefaultNavigatorOptions<ParamListBase, any, TabNavigationState<any>, ExpoTabsScreenOptions, TabNavigationEventMap, any>, 'activityEnabled' | 'children' | 'initialRouteName'> extended by:
Type: PropsWithChildren<UseTabsOptions>