如何回到导航器到主页

时间:2016-05-11 11:03:51

标签: react-native navigator

Hai我在反应原生中使用导航器,我在主屏幕中写了这样的导航器映射

LeftButton(route, navigator, index, navState){
    if(index > 0){
      return(
        <TouchableHighlight style={{marginTop: 10}}>
        <Text style={styles.arrow}>{arrow}</Text>
        </TouchableHighlight>
        )
    }else{
      return null
    }
  },

在三个屏幕之后,当我点击后面时我需要将屏幕移动到家,但是这里显示在屏幕之前,即使我在屏幕之前写了这样的navigator.push()

this.props.navigator.push({
      component: xxxx,
      title: 'xxxx',
      onLeftButtonPress:()=>{
        this.props.navigator.popToTop();
      }
    });

任何人都给我建议如何解决这个问题,任何帮助非常感谢

1 个答案:

答案 0 :(得分:0)

当我这样写的时候,我的代码正在运作

LeftButton(route, navigator, index, navState){
    if(index > 0){
      return(
        <TouchableHighlight style={{marginTop: 10}} onPress={() =>{
          if(route.name == 'xxx'){
            navigator.popToTop();
          }else if(index > 0){
            navigator.pop();
          }
        }}>
        <Text style={styles.arrow}>{arrow}</Text>
        </TouchableHighlight>
        )
    }else{
      return null
    }

在navigator.push中,我这样写了

this.props.navigator.push({
      name:'xxx',
      component: xxx,
    });
相关问题