繁体   English   中英

如何使用React JS检测Android / iOS手机中是否按下了后退按钮

[英]How to detect if the back button is pressed in android /ios phone using react js

我已经使用React js开发了一个响应式网站,并且我想在用户按下android / ios mobile的Back按钮时显示确认弹出窗口如何使用react js或node js检测手机中是否按下了back按钮

这是我的操作方式,假设我在仪表盘下有三个子路线,例如住家,数据和用户

 handleBackButton() {
  this._isMounted = true;
  window.onpopstate = ()=> {
   if(this._isMounted) {
    const { hash } = location;
    if(hash.indexOf('home')>-1 && this.state.value!==0)
      //Your action
    if(hash.indexOf('users')>-1 && this.state.value!==1)
     //Your action
    if(hash.indexOf('data')>-1 && this.state.value!==2)
      //Your action
  }
}

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM