React-Navigation后退按钮将我带到初始屏幕,而不是之前访问过的屏幕

时间:2018-05-13 19:22:25

标签: reactjs react-native redux react-navigation

我有一个顶级堆栈导航器

export const RootNavigator = StackNavigator({
MainScreen: {
screen: MainScreen,
navigationOptions: {
    gesturesEnabled: false,
    header: null,
},
},
Forgot: {
screen: forgot,
navigationOptions: {
    gesturesEnabled: false,
},
},
RegisterRouter: {
screen: RegisterRouter,
navigationOptions: {
    gesturesEnabled: false,
},  
....

class AppWithNavigationState extends React.Component {
 render() {
 const { dispatch, nav } = this.props;
return (
  <RootNavigator
    navigation={addNavigationHelpers({
      dispatch,
      state: nav,
      addListener,
    })}
  />
);
}
}

registerRouter是另一个堆栈导航器

const RegisterRouter = StackNavigator({
Register: {
    screen: Register,
    navigationOptions: {
        title: 'Registration',
        gesturesEnabled: false
    }
},
PersonalInfo: {
    screen: PersonalInfo,
    navigationOptions: {
        headerTitle: 'About you',
        gesturesEnabled: false
    }
},
PickPackage: {
    screen: PickPackage,
    navigationOptions: {
        title: 'Packages',
        gesturesEnabled: false
    }`

然而,无论何时按下后退按钮,我都会返回到MainScreen而不是之前的屏幕。

我按以下方式调用导航

onRegisterPress() {
  this.props.navigation.navigate('RegisterRouter');
}
<Button onPress={this.onRegisterPress.bind(this)} >
     Register
</Button>

我也在动作创建者中称之为

const navToQuestionaire = NavigationActions.navigate({
    routeName: 'PersonalInfo',
});
dispatch(navToQuestionaire);`

我不想在导航选项中手动使用headerleft我只是想让它正常导航,即返回之前访问过的屏幕。非常感谢您的帮助〜

1 个答案:

答案 0 :(得分:0)

原来我的导航选项阻止了子路由的标题,因此后退按钮始终与Root Navigator关联,所以它总是会返回那里。