這是我的問題的演示: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>
);
}
uj5u.com熱心網友回復:
backBehavior="history"
https://reactnavigation.org/docs/drawer-navigator#backbehavior
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/334950.html
上一篇:缺少包“metro-config”(ReactNative)
下一篇:當MarkerClusterGroup是父元素時,如何更改ReactMarkerClusterGroup的選項?
