This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo 路由器实验性 Stack
一个基于 react-native-screens 实验性 gamma stack、可选择启用的 Stack 同级组件。仅供测试使用。
重要
ExperimentalStack是一个 alpha API,适用于 Expo SDK 56 及更高版本。该 API 仅供测试使用——在可用于生产环境之前,API 和功能集可能会发生变化。
ExperimentalStack 是 Stack 的同类组件,由新的 react-native-screens/experimental 堆栈驱动。它需要按导航器选择启用:在要迁移的特定布局中,将 <Stack /> 替换为 <ExperimentalStack />,其他地方继续使用 <Stack />。
我们提前分享它,以便你可以在应用中试用并告诉我们还缺少什么。当前支持的选项范围有意保持精简,今后会逐步扩展。
有关适用于原生和 Web 应用的基于文件路由库的更多信息,请参阅 Expo Router 参考文档。
支持的功能
支持的屏幕选项:
titleheaderShownheaderTransparentheaderBackVisible
在 Android 上,ExperimentalStack 内置了对预测性返回手势的支持。你仍需在应用配置中将 android.predictiveBackGestureEnabled 设置为 true,以便为应用启用此功能。
平台支持
ExperimentalStack 仅适用于原生平台。在 Web 上,它会回退到标准的 Stack,因此相同的布局可以在各个平台上运行,无需条件代码。
基本用法
你可以像使用 Stack 一样组合使用 ExperimentalStack.Screen 和 ExperimentalStack.Protected。
已知限制
屏幕选项有限
ExperimentalStack 仅支持 title、headerShown、headerTransparent 和 headerBackVisible。传入任何其他选项(例如 headerLeft、headerRight、headerTitle、headerStyle、headerTintColor、动画覆盖选项、状态栏选项)都会记录开发警告且不起作用。对于需要这些选项的屏幕,请继续使用 <Stack />。
不能在 Android 上与 Stack 混用
在 Android 上,ExperimentalStack 和标准的 Stack 不能在同一个应用中共存——原生堆栈请选择一种导航器类型。我们希望在未来的版本中取消此限制,以便你可以一次迁移一个导航器。
信息 我们正在积极开发
ExperimentalStack,并期待收到反馈。你可以在 Discord 上分享想法、在 GitHub 上提交问题,或使用本页底部的 反馈 按钮。
安装
ExperimentalStack 是 expo-router 的一部分。如果你的项目中尚未安装 Expo Router,请按照 Expo Router 安装指南进行操作:
了解如何在项目中安装 Expo Router。
API
import { ExperimentalStack } from 'expo-router';
Components
Type: React.Element<Omit<Omit<StandardUseNavigationBuilderOptions<StackNavigationState<ParamListBase>, ExperimentalStackNavigationOptions, StandardExperimentalStackNavigationEventMap>, 'initialRouteName'> & Omit<object, 'initialRouteName'> & {
unstable_screenErrorBoundary: ComponentType<ErrorBoundaryProps>
}, 'children'> & Partial<Pick<Omit<StandardUseNavigationBuilderOptions<StackNavigationState<ParamListBase>, ExperimentalStackNavigationOptions, StandardExperimentalStackNavigationEventMap>, 'initialRouteName'> & Omit<object, 'initialRouteName'> & {
unstable_screenErrorBoundary: ComponentType<ErrorBoundaryProps>
}, '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.
Type: React.Element<StackScreenProps>
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.Titleinstead.
Type: React.Element<StackTitleProps>
Props
ExperimentalStackNavigationProp<ParamList, RouteName, NavigatorID>RouteProp<ParamList, RouteName>Types
Navigator-level events emitted by ExperimentalStack. Mirrors the subset of
NativeStackNavigationEventMap that the gamma Stack.Screen lifecycle
callbacks can drive.
Type: NavigationHelpers<ParamListBase, ExperimentalStackNavigationEventMap>
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.
Literal type: union
Acceptable values are: NavigationProp<ParamList, RouteName, NavigatorID, StackNavigationState<ParamList>, ExperimentalStackNavigationOptions, ExperimentalStackNavigationEventMap> | StackActionHelpers<ParamList>