事件发生时没有得到控制台。我试了很多次,都没能找到问题。当我评论删除listner的代码时,能够获得控制台。
const MyComponent = props => {
const onPopState = event =>{
console.log(event)
}
useEffect(() => {
window.addEventListener('popstate', onPopState);
return () => {
window.removeEventListener('popstate', onPopState);
};
}, []);
}
你可以试试这个
const MyComponent = props => {
const handlePopState = event =>{
console.log(event)
}
useEffect(() => {
window.addEventListener('popstate', handlePopState);
return () => {
window.removeEventListener('popstate', handlePopState);
};
}, []);
} ```