在嵌套StackNavigator之间进行本机导航 [英] React Native navigating between Nested StackNavigator

查看:64
本文介绍了在嵌套StackNavigator之间进行本机导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面有三个导航器,登录完成后我正在导航到DashBoard屏幕,但是当我想从DashBoard屏幕注销时遇到一个问题, this.props.navigation.navigate('Login ')工作正常,但我想在按下退出"按钮时清除堆栈.

I have the three navigators below, I am navigating to the DashBoard Screen after the login is completed but I have an issue when I want to logout from the DashBoard Screen, this.props.navigation.navigate('Login') is working fine but I want to clear the stack when signout button is pressed.

const DashBoardStackNavigator = createStackNavigator({
      DashBoard: DashBoard,
      Second:Second,
      Third:Third
    })


const BottomTabNavigator = createBottomTabNavigator({
  DashBoardStackNavigator,
  Account,
  Report,
  Members
}})

const AppStackNavigator = createStackNavigator({
  Login: Login,
  BottomTabNavigator: BottomTabNavigator

})


export default createAppContainer(AppStackNavigator)

我没有运气尝试过以下内容

I tried the following with no luck

const resetAction = StackActions.reset({
  index: 0,
  actions: [NavigationActions.navigate({ routeName: 'Login' })],
});
this.props.navigation.dispatch(resetAction);

错误:没有为键登录定义任何路由,必须是以下项之一 仪表板

Error: there is no route defined for key Login, Must Be one of DashBoard

推荐答案

尝试一下

 const navigateAction = StackActions.reset({
            index: 0,
            key: null,
            actions: [NavigationActions.navigate({ routeName: 'Login' })]
        })
        this.props.navigation.dispatch(navigateAction)

这篇关于在嵌套StackNavigator之间进行本机导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆