Navigate to specific screen from RootStackNavigator

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;

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

Thanks a lot


see this doc for more info:

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'

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

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