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
相关产品推荐
相关产品推荐

