0

I want to forbid BackButton closing app when in the root of the navigator. How can I detect current route?

Or maybe there is builtin react-native-navigation method to work with backbutton?

David Schumann
  • 13,380
  • 9
  • 75
  • 96
rendom
  • 3,417
  • 6
  • 38
  • 49

1 Answers1

1

Getting current Route

this.props.navigation.state.routeName;

Handle Back button

import { BackHandler } from 'react-native';

constructor(props) {
    super(props)
    this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
}

componentWillMount() {
    BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonClick);
}

componentWillUnmount() {
    BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
}

handleBackButtonClick() {
    //Handle ur back functionality here.
}
Prasanth S
  • 3,725
  • 9
  • 43
  • 75