Navigate to specific screen from RootStackNavigator


#1

Hi
I am receiving push notifs on RootStackNavigator::HandlePushNotification and I need to refresh a specific tab because new data has arrived in push notif.

When we are in a screen we use:

const { navigate } = this.props.navigation;
navigate(“Main”);

But when we are in RootStackNavigator, how can we navigate to Main or other screen?

Thanks a lot

Imo


#2

see this doc for more info: https://reactnavigation.org/docs/navigating-without-navigation-prop.html

basically you can set a ref on the RootStackNavigator, then call

this.navigatorRef.dispatch(NavigationActions.navigate({routeName: 'Main'})

where navigatorRef is just whatever you set the navigator ref name to, eg: <RootStackNavigator ref={nav => { this.navigatorRef = nav; }} />, and NavigationActions is imported from react-navigation like import { NavigationActions } from 'react-navigation'


#3

Thanks, but how to put that code inside a regular function (not inside render controls)


closed #4

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.