【问题标题】:How to navigate between different nested stacks in React Navigation 5.x?如何在 React Navigation 5.x 中的不同嵌套堆栈之间导航?
【发布时间】:2020-02-10 15:49:39
【问题描述】:

父导航器

  • 嵌套导航器 1

    • 屏幕A
    • 屏幕 B
  • 嵌套导航器 2

    • 屏幕C
    • 屏幕 D

如何在 React Navigation v5.0从屏幕 D 转到屏幕 B

我尝试了类似于https://reactnavigation.org/docs/en/navigation-actions.html#reset的方法

但是当我尝试使用 CommonActions.reset() 时,它会导航到屏幕 C

我试过了;

    ...
    import { CommonActions } from '@react-navigation/native';
    ...
    navigation.dispatch(
      CommonActions.reset({
        index: 1,
        routes: [
          { name: 'ScreenB' },
        ],
      })
    );
..

【问题讨论】:

  • 不是 index:1 指的是第二个嵌套导航器(包括 C 和 D)吗?你试过index:0 吗?

标签: reactjs react-native react-navigation


【解决方案1】:

【讨论】:

  • 我有一个 MessagesStack,我想导航到另一个堆栈“HomeStack”中的屏幕,它运行良好,但是当我单击返回按钮时,它会将我返回到初始屏幕“HomeStack”中的那个堆栈,而不是到 MessagesStack,有没有办法处理它来支持我到当前堆栈“MessagesStack”?
  • 要在任意嵌套的导航器之间导航,请参阅:medium.com/swlh/…“如果我们嵌套更多呢?”
猜你喜欢
  • 2021-05-29
  • 2020-11-07
  • 2021-12-23
  • 2021-09-02
  • 1970-01-01
  • 1970-01-01
  • 2020-06-02
  • 2023-03-22
  • 2020-05-25
相关资源
最近更新 更多