You need to enable JavaScript to run this app. React Navigation中不同导航器间跳转时如何显示初始屏幕
优惠活动
大模型
产品
解决方案
定价
更多

React Navigation中不同导航器间跳转时如何显示初始屏幕

嵌套导航器跳转保留访问状态问题解决

开发中使用了TabNavigator和StackNavigator两种导航器,为实现两个导航器之间的跳转,封装了RootStackNavigator,相关配置代码如下:

<RootStack.Screen
  name="AddOrderNavigator"
  component={AddOrderNavigator}
  options={{ animationEnabled: true, gestureEnabled: false, headerLeft: null }}
/>
<RootStack.Screen
  name="App"
  component={AppNavigator}
  options={{ animationEnabled: true, gestureEnabled: false, headerLeft: null }}
/>

该配置下功能整体运行正常,仅存在一处问题:在两个导航器之间跳转时,不会显示目标导航器的初始屏幕,而是保留之前的访问状态,直接展示跳转前停留在该导航器的页面。

解决方案

跳转时明确指定要打开的目标页面即可,参考代码如下:

navigation.push("AddOrderNavigator", {screen: 'DeliveryTypeScreen'});

内容的提问来源于stack exchange,提问作者Asma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 22:54:03