因此,我目前正试图在用户即将转到特定页面时生成一个触发器事件。例如,我在购物车页面上,决定返回到仪表板页面,我希望能够提示用户他将要离开购物车页面并返回仪表板页面。我如何在react native中做到这一点?
在按下的后退按钮上使用以下代码
onPressBack = () = {
// Works on both iOS and Android
Alert.alert(
'Alert Title',
'You are about to leave this screen',
[
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'OK', onPress: () => this.props.navigation.navigate('DashboardScreen') //code to navigate},
],
{ cancelable: false }
)
}