在导航器的根目录中,我想禁止BackButton关闭应用程序。 如何检测当前路线?
或者也许有内置的react-native-navigation方法可以与后退按钮一起使用?
答案 0 :(得分:1)
获取当前路线
this.props.navigation.state.routeName;
后退按钮
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.
}