This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

Expo 路由实验堆栈

一个基于 react-native-screens 实验性 gamma 栈构建的 Stack 可选择兄弟模块。仅可用于测试。

Android
iOS
Recommended version:
~57.0.3

重要 ExperimentalStack 是一个在 Expo SDK 56 及更高版本中可用的 alpha API。仅用于测试——在准备好用于生产之前,API 和功能集可能会发生变化。

ExperimentalStackStack 的兄弟组件,基于新的 react-native-screens/experimental 技术栈。它是按导航器可选的:在你想迁移的特定布局中将 <Stack /> 替换为 <ExperimentalStack />,在其他地方保持 <Stack /> 不变。

我们提前分享它,这样你可以在你的应用中尝试,并告诉我们缺少什么。支持的选项范围是故意有限的,会随着时间的推移而增加。

🌐 We are sharing it early so you can try it in your app and tell us what is missing. The supported option surface is intentionally narrow and will grow over time.

有关本地和 Web 应用的基于文件的路由库的更多信息,请参阅 Expo Router 参考资料。

支持的功能

🌐 Supported features

支持的屏幕选项:

🌐 Supported screen options:

  • title
  • headerShown
  • headerTransparent
  • headerBackVisible

在 Android 上,ExperimentalStack 提供了 预测返回手势 支持。你仍然需要通过在你的 应用配置 中将 android.predictiveBackGestureEnabled 设置为 true 来为你的应用启用它。

🌐 On Android, ExperimentalStack ships with predictive back gesture support. You still need to enable it for your app by setting android.predictiveBackGestureEnabled to true in your app config.

平台支持

🌐 Platform support

ExperimentalStack 仅限本地使用。在网页上,它会回退到标准的 Stack,因此相同的布局可以在各个平台上使用,而无需条件代码。

基本用法

🌐 Basic usage

app/_layout.tsx
import { ExperimentalStack as Stack } from 'expo-router'; export default function Layout() { return ( <Stack screenOptions={{ headerShown: true }}> <Stack.Screen name="index" options={{ title: 'Home' }} /> <Stack.Screen name="details" options={{ title: 'Details' }} /> </Stack> ); }

你可以以与 Stack 相同的方式组合 ExperimentalStack.ScreenExperimentalStack.Protected

🌐 You can compose ExperimentalStack.Screen and ExperimentalStack.Protected the same way you would with Stack.

已知的限制

🌐 Known limitations

有限的屏幕选项

ExperimentalStack 仅支持 titleheaderShownheaderTransparentheaderBackVisible。传入其他任何选项(例如 headerLeftheaderRightheaderTitleheaderStyleheaderTintColor、动画覆盖、状态栏选项)都会记录开发警告且不生效。对于需要这些选项的屏幕,请继续使用 <Stack />

还没有演示模式

ExperimentalStack 还不支持 presentation: 'modal'transparentModal。屏幕总是会压入堆栈。

还没有床单

ExperimentalStack 尚不支持 formSheet 或相关的表格尺寸/定位选项。

还没有自定义头

ExperimentalStack 还不支持自定义标题组件或标题着色/样式。只有上述列出的四个标题选项会生效。

还没有动画或状态栏自定义

ExperimentalStack 还不支持每屏动画覆盖(animationanimationDuration)或状态栏选项。

不能与 Android 上的 Stack 混合使用

在 Android 上,ExperimentalStack 和标准的 Stack 不能在同一个应用中共存——请为你的原生堆栈选择一种导航器类型。我们希望在未来的版本中取消这一限制,以便你可以一次迁移一个导航器。

🌐 On Android, ExperimentalStack and the standard Stack cannot coexist in the same app — pick one navigator type for your native stacks. We hope to lift this restriction in a future release so you can migrate one navigator at a time.

Web回退到标准堆栈

在网页上,<ExperimentalStack /> 渲染来自 expo-router 的标准 Stack。仅限原生的选项在网页上无效。

🌐 On Web, <ExperimentalStack /> renders the standard Stack from expo-router. Native-only options have no effect on Web.

信息 我们正在积极开发 ExperimentalStack 并寻求反馈。你可以在 Discord 分享你的想法,或者在 GitHub 上提交问题,也可以使用本页面底部的 反馈 按钮。

安装

🌐 Installation

ExperimentalStack 作为 expo-router 的一部分进行发布。如果你的项目中尚未安装,请按照 Expo Router 安装指南操作:

安装 Expo 路由

了解如何在项目中安装 Expo Router。

应用接口

🌐 API

import { ExperimentalStack } from 'expo-router';

Components

ExperimentalStack

Experimental

Type: React.Element<Omit<Omit<ExperimentalStackNavigatorProps, 'children' | 'initialRouteName' | 'layout' | 'screenListeners' | 'screenOptions' | 'screenLayout' | 'UNSTABLE_router' | 'UNSTABLE_routeNamesChangeBehavior' | 'id'> & DefaultRouterOptions<string> & { children: ReactNode; layout?: ((props: { state: StackNavigationState<ParamListBase>; navigation: NavigationHelpers<ParamListBase, {}>; descriptors: Record<...>; children: ReactNode; }) => ReactElement<...>) | undefined; ... 4 more ...; UNSTABLE_routeNamesChangeBehavior?: "firstMatch" | ... 1 more ... | undefined; ..., 'children'> & Partial<Pick<Omit<ExperimentalStackNavigatorProps, 'children' | 'initialRouteName' | 'layout' | 'screenListeners' | 'screenOptions' | 'screenLayout' | 'UNSTABLE_router' | 'UNSTABLE_routeNamesChangeBehavior' | 'id'> & DefaultRouterOptions<string> & { children: ReactNode; layout?: ((props: { state: StackNavigationState<ParamListBase>; navigation: NavigationHelpers<ParamListBase, {}>; descriptors: Record<...>; children: ReactNode; }) => ReactElement<...>) | undefined; ... 4 more ...; UNSTABLE_routeNamesChangeBehavior?: "firstMatch" | ... 1 more ... | undefined; ..., 'children'>>>

Renders the new react-native-screens/experimental native stack.

Sibling to Stack. Native-only — on web it falls back to the standard Stack. Opt-in per navigator: replace <Stack /> with <ExperimentalStack /> in the specific layout you want to migrate.

ExperimentalStack.Screen

Type: React.Element<StackScreenProps>

ExperimentalStack.Screen.BackButton

Type: React.Element<StackScreenBackButtonProps>

Component to configure the back button.

Can be used inside Stack.Screen in a layout or directly inside a screen component.

Example

import { Stack } from 'expo-router'; export default function Layout() { return ( <Stack> <Stack.Screen name="detail"> <Stack.Screen.BackButton displayMode="minimal">Back</Stack.Screen.BackButton> </Stack.Screen> </Stack> ); }

Example

import { Stack } from 'expo-router'; export default function Page() { return ( <> <Stack.Screen.BackButton hidden /> <ScreenContent /> </> ); }

Note: If multiple instances of this component are rendered for the same screen, the last one rendered in the component tree takes precedence.

Deprecated: Use Stack.Title instead.

ExperimentalStack.Screen.Title

Type: React.Element<StackTitleProps>

Props

Type: ExperimentalStackNavigationProp<ParamList, RouteName, NavigatorID>

route

Type: RouteProp<ParamList, RouteName>

Types

ExperimentalStackNavigationEventMap

Experimental

Navigator-level events emitted by ExperimentalStack. Mirrors the subset of NativeStackNavigationEventMap that the gamma Stack.Screen lifecycle callbacks can drive.

PropertyTypeDescription
gestureCancel{ data: undefined }
-
transitionEnd{ data: { closing: boolean } }
-
transitionStart{ data: { closing: boolean } }
-

ExperimentalStackNavigationHelpers

Type: NavigationHelpers<ParamListBase, ExperimentalStackNavigationEventMap>

ExperimentalStackNavigationOptions

Experimental

Options accepted by ExperimentalStack screens. Mirrors the narrow option surface of the gamma <Stack.HeaderConfig> component from react-native-screens/experimental. Anything outside this shape is dropped with a __DEV__ warning at runtime.

PropertyTypeDescription
headerBackVisible(optional)boolean
-
headerShown(optional)boolean
-
headerTransparent(optional)boolean
-
title(optional)string
-

ExperimentalStackNavigationProp

Literal Type: union

Acceptable values are: NavigationProp<ParamList, RouteName, NavigatorID, StackNavigationState<ParamList>, ExperimentalStackNavigationOptions, ExperimentalStackNavigationEventMap> | StackActionHelpers<ParamList>