反应导航推送多个屏幕

问题描述 投票:0回答:2

我正在尝试使用我的React本机项目上的简单导航进行导航。当导航到屏幕A到B然后用Android后退按钮返回时,下次导航A到B然后B到C.反应导航器推送多个C屏幕。任何想法都会很棒。干杯。

  //stack navigator 
  const StackScreense = StackNavigator({
    A: { screen: A},
    B: { screen: B},
    C: { screen: C},
   }, {
      initialRouteName: 'A',
      navigationOptions:{ header: null},
      initialRouteParams: { status: ' ' }
    });
  //navigation
  this.props.navigation.navigate('B');

  this.props.navigation.navigate('C', {
      params
    });
react-native react-navigation
2个回答
1
投票

我正在使用socket.io忘记卸载监听器。那就是问题所在。


0
投票

以编程方式,您可以使用以下解决方案,检查下一个屏幕routeName是否与前一个屏幕routeName不相似,前提是您正在调用NAVIGATE操作

这是中间件

const navigateOnce = getStateForAction => (action, state) => {
  const { type, routeName } = action
  return state &&
    type === NavigationActions.NAVIGATE &&
    routeName === state.routes[state.routes.length - 1].routeName
    ? null
    : getStateForAction(action, state)
}

用法

YourStackRouter.router.getStateForAction = navigateOnce(
  YourStackRouter.router.getStateForAction
)
© www.soinside.com 2019 - 2024. All rights reserved.