【问题标题】:React-native navigation is it possible to intercept the back action?React-native 导航是否可以拦截后退操作?
【发布时间】:2022-01-06 17:43:19
【问题描述】:

是否可以在任何路线上拦截本机反应的后退动作? 假设我在一个页面上,当用户执行返回操作时,我想在不同的路径上导航用户。

甚至弹出确认。

【问题讨论】:

标签: javascript react-native


【解决方案1】:

你可以使用 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 2018-09-12
    • 1970-01-01
    • 2019-10-07
    相关资源
    最近更新 更多