在反应导航中从嵌套堆栈跳到根中的一个屏幕

时间:2019-04-27 15:48:42

标签: reactjs react-native react-navigation

我在使用React导航的React Native项目中具有以下根源: https://i.stack.imgur.com/NA2gd.jpg

main是带有3个屏幕的bottomTabNavigator,在配置文件屏幕中,我具有3个屏幕的topTabNavigator。 在EditProfile屏幕中,我有一个注销按钮。当我按下注销按钮时,我想导航到“登录”屏幕。请帮助我解决这个问题

1 个答案:

答案 0 :(得分:0)

我自己发现了它 在“个人资料”屏幕中,我像这样使用screenProps:

class Profile extends Component{
    constructor(props){
      super(props);
    }
    render(){
        return(
            <View style={{ flex: 1,}}>        
            <AppNavigator screenProps={{ rootNavigation: this.props.navigation }}/>
             </View>
        )
    }
}

,然后在EditProfile页面中,当用户触摸注销按钮时,我运行以下代码:

this.props.screenProps.rootNavigation.navigate('login')