Во-первых, вы должны написать вспомогательный класс для независимой навигации.
import { NavigationActions } from 'react-navigation';
class NavigationService{
_navigator = null;
currentRoute = null;
isNavigated = false;
setTopLevelNavigator(navigatorRef) {
_navigator = navigatorRef;
}
navigate(routeName, params) {
_navigator.dispatch(
NavigationActions.navigate({
type: NavigationActions.NAVIGATE,
routeName,
params,
})
);
}
setCurrentRoute(routName){
this.currentRoute = routName;
}
setNavigated(status){
this.isNavigated = status;
}
}
// add other navigation functions that you need and export them
const Navigation = new NavigationService();
export default Navigation;
Затем вы импортируете этот класс на свою домашнюю страницу.
import NavigationHelper from './NavigationService'; // Path can change according to you
const HomePage = () => {
NavigationHelper.navigate('Login');
return(//Sometihng);
}