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 可选择兄弟模块。仅可用于测试。
重要
ExperimentalStack是一个在 Expo SDK 56 及更高版本中可用的 alpha API。仅用于测试——在准备好用于生产之前,API 和功能集可能会发生变化。
ExperimentalStack 是 Stack 的兄弟组件,基于新的 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:
titleheaderShownheaderTransparentheaderBackVisible
在 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
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.Screen 和 ExperimentalStack.Protected。
🌐 You can compose ExperimentalStack.Screen and ExperimentalStack.Protected the same way you would with Stack.
已知的限制
🌐 Known limitations
有限的屏幕选项
ExperimentalStack 仅支持 title、headerShown、headerTransparent 和 headerBackVisible。传入其他任何选项(例如 headerLeft、headerRight、headerTitle、headerStyle、headerTintColor、动画覆盖、状态栏选项)都会记录开发警告且不生效。对于需要这些选项的屏幕,请继续使用 <Stack />。
不能与 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 Router。
应用接口
🌐 API
import { ExperimentalStack } from 'expo-router';
Components
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.
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.
| Property | Type | Description |
|---|---|---|
| gestureCancel | {
data: undefined
} | - |
| transitionEnd | {
data: {
closing: boolean
}
} | - |
| transitionStart | {
data: {
closing: boolean
}
} | - |
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.
| Property | Type | Description |
|---|---|---|
| headerBackVisible(optional) | boolean | - |
| headerShown(optional) | boolean | - |
| headerTransparent(optional) | boolean | - |
| title(optional) | string | - |
Literal Type: union
Acceptable values are: NavigationProp<ParamList, RouteName, NavigatorID, StackNavigationState<ParamList>, ExperimentalStackNavigationOptions, ExperimentalStackNavigationEventMap> | StackActionHelpers<ParamList>