fade
fade

Reputation: 1

React navigation 6 ( navigate to another stack and specific screen)

I'm using react navigate V6 and I want to move between stacks , but this code is not working :

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

@react-navigation/native is not working with V6

Upvotes: 0

Views: 1054

Answers (1)

ND verma
ND verma

Reputation: 297

work for me

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

Upvotes: 0

Related Questions