2017-06-03 36 views
0

我正在使用React-Navigation,導航欄遇到問題。 我有一個名爲LoginScreen的頁面,它在登錄後將用戶移動到HomeScreen。 我的問題是我在主屏幕上有一個「後退」按鈕,因此我可以返回到登錄屏幕(我不想要)這是代碼:刪除「返回」按鈕

LoginScreen(其中我瀏覽到主屏幕):

handlePress(navigate){ 
    firebaseRef.auth().signInWithEmailAndPassword(this.state.email, this.state.password).then(function(firebaseUser){ 
     //Success, move to homepage. 
     navigate("Home"); 
    }).catch(function(error){ 
     //Failed to log in, print error. 
    }); 
} 

導航裏面render()

const { navigate } = this.props.navigation; 

這就是我所說的handlePress:

<TouchableOpacity style={styles.logBtn} onPress={()=>this.handlePress(navigate)}> 
    <Text style={styles.logTxt}> 
    Login 
    </Text> 
</TouchableOpacity> 

我搜索了一下,並嘗試在handlePress中寫navigate.replace("Home");,但它只是不會導航。

我在做什麼錯?

回答

1

我想爲你做的最好的事情是重置,您可以與復位做導航:

import { NavigationActions } from 'react-navigation'; 


    const resetAction = NavigationActions.reset({ 
     index: 0, 
     actions: [ 
     NavigationActions.navigate({ routeName: 'Home'}) 
     ] 
    }) 
    this.props.navigation.dispatch.(resetAction); 

你可以找到這樣或閱讀更多有關在這裏react-navigation-doc

,或者你可以改變您的主屏幕導航配置其功能後退按鈕圖標

static navigationOptions = { 
     title: 'Home', 
     header: ({ navigate }) => { 
     {/* left here refers to the left back button */} 
      let left = (
       <TouchableOpacity onPress={() => navigate('Profile')} > 
        <Icon name="ios-menu-outline" 
        size={25} style={{ paddingRight: 5, paddingLeft: 20 }} 
        color="#ffffff" /> 
       </TouchableOpacity> 
      ); 
      let style = { backgroundColor: '#00AFEF',elevation: 0,shadowOpacity: 0,}; 
      let titleStyle = { color: '#ffff', fontSize: 25, fontFamily: 'Arial' }; 
      return { left, style, titleStyle } 
     }, 
    } 
+0

謝謝。 NavigationActions工作得很好。 –

0
static navigationOptions={ 
    title:'Categories', 
    headerLeft: (<View></View>), }; 

適用於我;)