How to reset a Stack in a different Tab using React Navigation 5.x

前端 未结 1 756
-上瘾入骨i
-上瘾入骨i 2021-02-15 23:10

My app has a TabNavigator with a StackNavigator in each Tab. I\'m not resetting the stacks when navigating between them by clicking on different tabs, so when you change tab, th

1条回答
  •  死守一世寂寞
    2021-02-15 23:52

    In the end I was able to use the reset action to do this. I dispatched nested state for the tab I wanted to reset:

    navigation.dispatch(
      CommonActions.reset({
        routes: [
          {
            name: 'tab-route-name',
            state: {
              routes: [
                { name: 'stack-route-1' },
                { name: 'stack-route-2' },
                { name: 'stack-route-3' }
              ]
            }
          }
        ]
      })
    )
    

    It seems to be clever enough that as long as the tab navigator is a parent of the current route, it will find it and reset it.

    0 讨论(0)
提交回复
热议问题