【问题标题】:How to navigate to a Screen without adding it to backstack?如何导航到屏幕而不将其添加到后台堆栈?
【发布时间】:2020-07-09 19:47:23
【问题描述】:

我的导航器是:

const MyStack = createStackNavigator();

const MyRoutes= () => (
  <MyStack.Navigator headerMode='none' initialRouteName='First'>
    <MyStack.Screen name='First' component={ScreenFirst} />
    <MyStack.Screen name='Second' component={ScreenSecond} />
  </MyStack.Navigator>
);

我的实际流程是:

First -> (next) -> Second -> (back) -> First

但我想显示First 路由而不将其添加到后台堆栈,所以它会是:

First -> (next) -> Second -> (back) -> (default OS behavior)

有可能吗?如果是,如何?我正在使用"@react-navigation/native": "^5.6.1"

我知道我可以控制 Second 路由中的 Back 行为,但由于在 Android (Java/Kotlin) 中可以显示片段而不将其添加到后台堆栈,我想 React Native 中存在类似的东西。

【问题讨论】:

    标签: javascript react-native react-native-navigation


    【解决方案1】:

    您可以使用navigation.replace('Second')。更多信息在这里https://reactnavigation.org/docs/stack-actions#replace

    【讨论】:

      猜你喜欢
      • 2020-05-07
      • 2020-07-27
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多