我正在使用react navigate V6,我想在堆栈之间移动,但这段代码不起作用:
navigation.navigate("Stack Name", { screen: "screen Name" });
@react-navigation/native不适用于V6
@react-navigation/native
wmomyfyw1#
"为我工作"
import { createStackNavigator } from '@react-navigation/stack'; const MyStack = createStackNavigator(); const SettingsStack = createStackNavigator(); function HomeStackScreen() { return ( <MyStack.Navigator> <MyStack.Screen name="Home" component={HomeScreen} /> <MyStack.Screen name="Details" component={DetailsScreen} /> </MyStack.Navigator> ); } function SettingsStackScreen() { return ( <SettingsStack.Navigator> <SettingsStack.Screen name="Settings" component={SettingsScreen} /> <SettingsStack.Screen name="Profile" component={ProfileScreen} /> </SettingsStack.Navigator> ); } import { useNavigation } from '@react-navigation/native'; function HomeScreen() { const navigation = useNavigation(); const handlePress = () => { navigation.navigate('Settings', { screen: 'Profile' }); }; return ( <Button title="Go to Profile" onPress={handlePress} /> ); }
1条答案
按热度按时间wmomyfyw1#
"为我工作"