我正在尝试使用我的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
});
我正在使用socket.io忘记卸载监听器。那就是问题所在。
以编程方式,您可以使用以下解决方案,检查下一个屏幕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
)