React Native,reactnavigation,如何使用 Drawer 返回()到上一個屏幕,而不是第一個屏幕?

傻瓜123

這是我的問題的演示:https : //snack.expo.dev/xtklvo6eM

我想從 ScreenOne -> ScreenTwo -> ScreenThree -> goBack() 到 ScreenTwo ....

但是在 ScreenThree 上調用 navigation.goBack() 會讓我回到 ScreenOne,而不是 ScreenTwo。

有人能告訴我這是為什麼嗎?

import * as React from 'react';
import { Button, View } from 'react-native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';

function ScreenOne({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button
        onPress={() => navigation.navigate('ScreenTwo')}
        title="Go to screen two"
      />
    </View>
  );
}

function ScreenTwo({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button onPress={() => navigation.navigate('ScreenThree')} title="Go to screen three" />
    </View>
  );
}

function ScreenThree({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button onPress={() => navigation.goBack()} title="Try to go back to screen two.." />
    </View>
  );
}

const Drawer = createDrawerNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Drawer.Navigator initialRouteName="ScreenOne">
        <Drawer.Screen name="ScreenOne" component={ScreenOne} />
        <Drawer.Screen name="ScreenTwo" component={ScreenTwo} />
        <Drawer.Screen name="ScreenThree" component={ScreenThree} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

返回特定屏幕,而不是第一个屏幕react-native-navigation

如何使用 React Navigation Drawer 切换屏幕

Libgdx:如何返回上一個屏幕

在React-Native中使用Drawer-Navigator导航到另一个导航器后,为什么会出现空白屏幕?

如何从React-Native中的另一个组件打开/关闭Drawer

使用 React Native 防止返回上一个屏幕

如何将react-native-router-flux与react-native-drawer结合使用

React Native-ReactNavigation.addNavigationHelpers不是函数

如何使用 goBack() 函数返回 React Native 中的上一个屏幕?

React Native Drawer和Tab Navigator

'@reactnavigation/drawer 和 @reactnavigation/native 在我的 react native 代码中没有得到解决。我该怎么办?

如何修复 React Native 中的 ReactNavigation 错误

如何在react native和reactnavigation中导航到其他屏幕时删除顶部选项卡导航器

如何在CustomDrawerContent内使用props.navigation.closeDrawer()?(React Native)(“ @ react-navigation / drawer”:“ ^ 5.11.4”)

如何在React Native中实现Drawer导航器?

react-native:如何结合 react-native-router-flux 和 react-native-drawer?

如何使用 combine v5 在 React Native 中使用 Stack 和 Drawer

如何将屏幕从App.js导航到React-Native中的第一个屏幕

React Native useEffect 在同一屏幕或返回屏幕时不起作用

如何在 react-native 中結合使用 Drawer Navigator 和 Stack Navigator?

从不同导航器(React Native)的另一个屏幕返回时如何刷新屏幕?

如何使用React Native打开屏幕

如何使用React Native检测屏幕解锁?

Material-UI:如何在与 react-router-dom 一起使用时删除某些路由中的 Drawer?

如何将React Router与Material UI Drawer一起使用以更改点击内容?

如何在React Native中显示一次屏幕?

WIX React Native Navigation:堆栈中的第二个屏幕显示在第一个屏幕上方

React Native:将参数传递给 Drawer.Navigator

React Native Navigation Drawer-打开页面不在抽屉中