【发布时间】:2018-06-01 20:30:57
【问题描述】:
我已经使用 React js 开发了一个响应式网站。我想在用户按下 android/ios 手机的后退按钮时显示确认弹出窗口如何使用 react js 或节点检测手机中是否按下了后退按钮js
【问题讨论】:
标签: javascript reactjs
我已经使用 React js 开发了一个响应式网站。我想在用户按下 android/ios 手机的后退按钮时显示确认弹出窗口如何使用 react js 或节点检测手机中是否按下了后退按钮js
【问题讨论】:
标签: javascript reactjs
这就是我的做法,假设我在仪表板下有三个子路由,例如主页、数据和用户
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
}
}
}
【讨论】: