【发布时间】:2018-01-20 13:43:53
【问题描述】:
我在 android 设备的后退按钮上遇到了一个问题。当我登录应用程序并转到主屏幕并从主屏幕时,如果我按下设备返回按钮,那么它会再次重定向到我的登录屏幕而不是背景。
请帮助我在应用程序成功登录应用程序(即从主屏幕)后按返回按钮时应用程序如何进入后台状态。
这是我的代码,
Login.js
//Click on login button call this method
home()
{
const { navigate } = this.props.navigation;
navigate('Home', { name: 'Home'});
}
Home.js:
constructor(props) {
super(props)
this.handleBackButtonClick = this.handleBackButtonClick.bind(this);
}
componentWillMount()
{
console.disableYellowBox = true;
console.log(this.props.navigation.state.routeName);
this.callapi();
}
componentWillUnmount() {
BackHandler.removeEventListener('hardwareBackPress', this.handleBackButtonClick);
}
handleBackButtonClick() {
if (this.props.navigation.state.routeName == 'Home') {
// this.props.navigation.goBack(null);
// BackHandler.exitApp()
this.props.navigation.dispatch(resetAction)
}
return false;
}
【问题讨论】:
-
你用的是什么类型的路由器?
-
我正在使用 react-navigation。
标签: react-native react-navigation