뒤로 및 앞으로 브라우저 단추 이벤트를 수신 대기하려면 이벤트 처리기를 window.onpopstate
사용하고 있습니다. 내 코드는 다음과 같은 :window.onpopstate -이 이벤트 핸들러를 제거해야합니까?
componentDidMount() {
window.onpopstate = this.onBackOrForwardButtonEvent;
}
onBackOrForwardButtonEvent = (e) => {
e.preventDefault();
log.info('back or forward button pressed');
if (this.props.route.path !== '/app') {
// ... do something
}
};
내 질문 :이 이벤트 리스너를 제거해야합니까 - 아마도 componentWillUnmount
에? 같은
뭔가 : 나는 때 구성 요소 마운트 해제 리스너를 제거 위에서하지만 결코 가지고있는 것처럼 내가 onPopState
를 사용하는 예를 본 적이
componentWillUnmount() {
window.removeEventListener('onpopstate', this.onBackOrForwardButtonEvent, false)
}
.
예 : https://github.com/ReactTraining/react-router/issues/967