簡體   English   中英

React-native 導航可以攔截后面的動作嗎?

[英]React-native navigation is it possible to intercept the back action?

是否可以在任何路線上攔截本機反應的后退動作? 假設我在一個頁面上,當他/她執行返回操作時,我想在不同的路線上導航用戶。

甚至彈出確認。

例如,您可以使用 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM