Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

171
Vistas
React Native: How to navigate from inside the NavigationContainer?

I have a component in my Navigation.tsx which controls the routes within my application. The component sits inside one of my Stack.Screen's under headerRight . Im trying to navigate to a different screen when the component is clicked. However, im unable to get that working for this particular component. Routing outside my Navigation file works perfectly fine, but not within.

Im unable to figure out what i am missing or what needs to be changed.

Code below: headerRight under ItemDetails

export default function Navigation( { navigation }) {
const Stack = createStackNavigator();

const MyTheme = {
    ...DefaultTheme,
    colors: {
      ...DefaultTheme.colors,
      background: '#FFF',
    }
}

return (
    <NavigationContainer theme={MyTheme}>
        <Stack.Navigator initialRouteName="Home">

            <Stack.Screen name="Home" component={Home} options={({route}) => ({
                headerShown: false,
            })}/>
            <Stack.Screen name='CartDetails' component={CartDetails}/>
            <Stack.Screen name="ItemDetails" component={ItemDetails} options={({route}) => ({
                title: false,
                headerTitle: false,
                headerBackTitleVisible: false,
                headerTransparent: true,
                headerShadowVisible: false,
                headerRight: () => (
                    <TouchableOpacity onPress={() => { navigation.navigate('CartDetails')}}>
                        <CartIcon />
                    </TouchableOpacity>
                ),
                headerBackImage: () => (
                    
                        <View style={{backgroundColor: '#ffffff', borderRadius: '50%', marginLeft: 15, marginBottom: 5}}>
                            <Entypo name="chevron-small-left" size={30} color="#37BD6B"/>
                        </View>
                )
            })} />

        </Stack.Navigator>
    </NavigationContainer>
)

}

Thanks in advance

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I managed to solve the problem.

Rather than passing headerRight an argument, passing it to 'option' gives you the correct result.

 options={({route, navigation}) => ({ 
                title: false,
                headerTitle: false,
                headerBackTitleVisible: false,
                headerTransparent: true,
                headerShadowVisible: false,
                headerRight: () => (
                    <TouchableOpacity onPress={() => navigation.navigate('CartDetails')}>
                        <CartIcon />
                    </TouchableOpacity>
                ),
                headerBackImage: () => (
                    
                        <View style={{backgroundColor: '#ffffff', borderRadius: '50%', marginLeft: 15, marginBottom: 5}}>
                            <Entypo name="chevron-small-left" size={30} color="#37BD6B"/>
                        </View>
                )
            })}  />
about 4 years ago · Juan Pablo Isaza Denunciar

0

React Navigation provides the navigation object as an argument to the header callbacks. You can take it from there.

  headerRight: ({ navigation }) => (
    <TouchableOpacity onPress={() => { navigation.navigate('CartDetails')}}>
      <CartIcon />
    </TouchableOpacity>
  ),
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda