【发布时间】:2022-01-06 17:43:19
【问题描述】:
是否可以在任何路线上拦截本机反应的后退动作? 假设我在一个页面上,当用户执行返回操作时,我想在不同的路径上导航用户。
甚至弹出确认。
【问题讨论】:
是否可以在任何路线上拦截本机反应的后退动作? 假设我在一个页面上,当用户执行返回操作时,我想在不同的路径上导航用户。
甚至弹出确认。
【问题讨论】:
你可以使用 React 的 [BackHandler][1] 例如
// import the back handler from react-native
import { BackHandler } from 'react-native'
// fire the listener on every render (including the componentWillUnmount)
useLayoutEffect(() => {
BackHandler.addEventListener(
"hardwareBackPress",
{
console.warn('about to go back....')
}
);
}, [])
[1]: https://reactnative.dev/docs/backhandler
【讨论】: