1

我的代码类似于以下。假设目前我的导航堆栈历史是:

屏幕 A> 屏幕 B> 屏幕 D。

从屏幕 D 按下按钮我想重置我的导航堆栈状态/历史,如下所示:屏幕 A> 屏幕 F

但我收到此错误:

  The action 'RESET' with payload {"index":1,"routes":[{"name":"Screen A"},{"name":"Screen F"}]} was not handled by any navigator.
<Stack.Navigator>
  <Stack.Screen name="TabNavigator" component={TabNavigator} />
  <Stack.Screen name="Screen E" component={ScreenE} />
  <Stack.Screen name="Screen F" component={ScreenF} />
  <Stack.Screen name="Screen G" component={ScreenG} />
</Stack.Navigator>
<Tab.Navigator>
  <Tab.Screen name="Screen A" component={ScreenA} />
  <Tab.Screen name="Screen B" component={ScreenB} />
  <Tab.Screen name="Screen C" component={ScreenC} />
  <Tab.Screen name="Screen D" component={ScreenC} />
</Tab.Navigator>

const ScreenD=({navigation})=>{ <Button title="reset stack" onPress={()=> navigation.reset({
        index: 1,
         routes: [{ name: "Screen A" }, { name: "Screen F" }],
       })} /> }
4

1 回答 1

1

从这里使用 CommonActions.reset() https://reactnavigation.org/docs/navigation-actions

这工作得很好。

于 2021-07-14T16:44:45.110 回答