首页 > 解决方案 > 在反应导航中从嵌套堆栈跳转到根目录中的一个屏幕

问题描述

我使用反应导航在我的反应原生项目中有以下根源: https ://i.stack.imgur.com/NA2gd.jpg

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

标签: reactjsreact-nativereact-navigation

解决方案


我在个人资料屏幕中自己找到了它,我像这样使用 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')


推荐阅读