Disable back button in react navigation

前端 未结 18 1608
长发绾君心
长发绾君心 2020-12-12 18:31

I\'m using react native navigation (react-navigation) StackNavigator. it starts from the Login page throughout the whole lifecycle of the app. I don\'t want to have a back

相关标签:
18条回答
  • 2020-12-12 19:31

    For the latest version React Navigation 5 with Typescript:

    <Stack.Screen
        name={Routes.Consultations}
        component={Consultations}
        options={{headerLeft: () => null}}
      />
    
    0 讨论(0)
  • 2020-12-12 19:31

    In Latest Version (v2) works headerLeft:null. you can add in controller's navigationOptions as bellow

    static navigationOptions = {
        headerLeft: null,
    };
    
    0 讨论(0)
  • 2020-12-12 19:32

    using the BackHandler from react native worked for me. Just include this line in your ComponentWillMount:

    BackHandler.addEventListener('hardwareBackPress', function() {return true})
    

    it will disable back button on android device.

    0 讨论(0)
  • 2020-12-12 19:32

    For latest version of React Navigation, even if you use null in some cases it may still show "back" written!

    Go for this in your main app.js under your screen name or just go to your class file and add: -

    static navigationOptions = {
       headerTitle:'Disable back Options',
       headerTitleStyle: {color:'white'},
       headerStyle: {backgroundColor:'black'},
       headerTintColor: 'red',
       headerForceInset: {vertical: 'never'},
       headerLeft: " "
    }
    
    0 讨论(0)
  • 2020-12-12 19:33

    react-navigation versions >= 1.0.0-beta.9

    navigationOptions:  {
       headerLeft: null
    }
    
    0 讨论(0)
  • 2020-12-12 19:33

    ReactNavigation v 5.0 - Stack option:

    options={{
    headerLeft: () => { 
     return <></>; 
    }
    }}
    
    0 讨论(0)
提交回复
热议问题