0

我想在导航器的根目录中禁止 BackButton 关闭应用程序。如何检测当前路线?

或者也许有内置的 react-native-navigation 方法可以使用后退按钮?

4

1 回答 1

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.
}
于 2018-10-22T06:38:41.487 回答