React 导航中 Stack 和 Swtich Navigator 之间的嵌套导航器之间的导航

Navigation between nested navigator between Stack and Swtich Navigator in react navigation

您好,我的导航有 RootNavigator,如下所示;

const App = createSwitchNavigator(
  {
    Auth: AuthNavigator,
    App: HomeNavigator,
    Seller: SellerNavigator
  },
  {
    initialRouteName: "Auth",
    headerMode: "none"
  }
);

场景

Auth contains login ,signup etc . App contains home,etc. When user is logged in ,he is now App Navigator.

What i want when user press Logout ,i want to move user properly from App navigator to Auth navigator

我试过了StackNavigation and NavigationActions

代码

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

错误

请指导我如何在 React 导航中正确操作?

谢谢

您不能在那里使用堆栈操作,因为 Auth 不是堆栈导航器的一部分。

您可以做的只是 navigation.navigate('Auth') 从注销组件。这会将用户带到 Auth 导航器中,因为 AuthApp 是切换导航器的一部分,他将无法 go backApp stack 这是你想要的行为,在这种情况下,它与使用 StackActions.reset.

相同