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?
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?
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.
}