react-native-navigation v2:获取当前路线

时间:2018-10-22 06:04:36

标签: javascript react-native-navigation react-native-navigation-v2

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

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

1 个答案:

答案 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.
}