react-native 阻止路由返回监听
const goBack = (onBack?: () => void) => {
const isSave = true
const onBackFn = onBack ? onBack : navigation.goBack
if (!isSave) {
onBackFn()
return
}
Modal.alert('', <Text>当前内容已修改,是否存为草稿?</Text>, [
{
text: '否',
onPress: () => {
onBackFn()
}
},
{
text: '是',
onPress: () => {
onSubmitDraft(onBackFn)
}
}
])
})
}
const navigationBeforeRemove = () => {
const l = navigation.addListener('beforeRemove', e => {
console.log(11)
// Prevent default behavior of leaving the screen
e.preventDefault()
// Prompt the user before leaving the screen
goBack(() => {
navigation.dispatch(e.data.action)
})
})
}
本文标题:react-native 阻止路由返回监听
本文链接:https://www.haomeiwen.com/subject/zieeidtx.html
网友评论