问题描述
在chrome里面从a页面跳转到该页面之后必须和浏览器交互(比如点击页面)之后再点击浏览器的后退按钮才能正常触发popstate的跳转,在firfox正常监听操作前进后退跳转两次之后也失效
问题出现的环境背景及自己尝试过哪些方法
MacOS,Chrome75.0.3770.100 firfox最新版
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
import React, { Component } from 'react'
export default class NotFound extends Component {
componentDidMount(){
this.goBack()
}
componentWillUnmount(){
window.removeEventListener('popstate',this.goNewPage)
}
goBack=()=>{
window.history.pushState(null,'', document.URL)
window.addEventListener('popstate', this.goNewPage)
}
goNewPage=()=>{
window.location.href='https://www.baidu.com'
}
render() {
return (
aaa
)
}
}