簡體   English   中英

在 React 中,單擊瀏覽器后退按鈕時,我應該單擊一個 DOM 元素(例如,按鈕)並且應該在同一個組件中

[英]In React, On clicking browser back button I should click one DOM ele(for instance, button) and should be in the same component

window.addEventListener('beforeunload', () => {
      document.getElementById('sample-button').click()
    })

應該添加哪個事件監聽器?

如果您正在使用類組件,例如

class pp extends React.Component {

  //This method is called when a component is being removed from the DOM:
  componentWillUnmount()
  {
     document.getElementById('sample-button').click()
  }

  render(){
    return ...
}

} 

暫無
暫無

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

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