如何重置堆栈导航器,然后导航到选项卡导航器中的选项卡?

How to reset the stack navigator and then navigate to a Tab in Tab navigator?

我的代码如下所示

onPress={() => {
  const resetAction = StackActions.reset({
    index: 0,
    key: "Tab1",
    actions: [navigation.navigate({ routeName: "Tab1" })]
  });

  navigation.dispatch(resetAction);
}}

我想通过重置堆栈从堆栈导航器的第二个屏幕导航到 Tab1。我没有为此使用 Redux。以目前的方式,我要么能够重置堆栈,要么移动到 Tab1 页面(它被添加为堆栈上的单独屏幕)。 我想先重置堆栈,然后转到 Tab1 屏幕。有什么办法可以实现吗?

这是我的成功范例

代码会打开两个屏幕,根据index判断显示哪个屏幕在前面,index0:显示第一个,index1:显示第二个(此处将显示 tab1 屏幕)

希望对你有所帮助

import { NavigationActions } from 'react-navigation';

const resetAction = NavigationActions.reset({
  index: 1,
  actions: [
    NavigationActions.navigate({ routeName: 'home' }),
    NavigationActions.navigate({ routeName: 'Tab1' })
  ]
})

this.props.navigation.dispatch(resetAction);