React导航6(导航到另一个堆栈和特定屏幕)

gab6jxml  于 2023-02-19  发布在  React
关注(0)|答案(1)|浏览(131)

我正在使用react navigate V6,我想在堆栈之间移动,但这段代码不起作用:

navigation.navigate("Stack Name", { screen: "screen Name" });

@react-navigation/native不适用于V6

wmomyfyw

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} />
  );
}

相关问题