从堆栈外部重置堆栈导航堆栈

Reset a stack navigation stack from outside the stack

我想在注销用户时重置堆栈导航堆栈。目前,如果我注销,我的用户将被带到我使用 switchNavigator 的授权屏幕,如果用户重新登录,他们将被带到他们注销时上次使用的屏幕。我希望用户在注销然后再次登录后被定向到客户提要。

我的导航器是这样的

export const Tabs = DrawerNavigator(
  {
    AuthLoading: AuthLoading,
    Auth: UnAuthenticatedTabs,
    App: AuthenticatedTabs
  },
  {
    contentComponent: SideMenu,
    initialRouteName: 'AuthLoading',
  }
);

const UnAuthenticatedTabs = SwitchNavigator({
  LogIn: { screen: SignIn },
  Registration: { screen: Registration },
  ForgotPassword: { screen: ForgotPassword }
})

const AuthenticatedTabs = StackNavigator({
  CustomerFeed: { screen: CustomerFeed,
    navigationOptions: ({ navigation }) => ({
      title: 'Customer Feed',
    })
   },
  Customer: { screen: Customer,
    navigationOptions: ({ navigation }) => ({
      title: 'Customer'
    })
  },
})

最终对我有用的是在用户登录并路由到 stackNavigator 时重置堆栈。不是在用户注销并路由到 switchNavigator 时尝试重置 stackNavigator 时。

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