Answers for "react prevent back"

1

react prevent back

const preventBack = (): void => {
  window.history.pushState(null, "", window.location.pathname);
}

const handleBack = (): void => {
  console.log('handleBack')
}

useEffect(() => {
  preventBack();
  window.addEventListener('popstate', handleBack);
  return () => {
    window.removeEventListener('popstate', handleBack)
  }
});
Posted by: Guest on February-04-2021

Code answers related to "react prevent back"

Code answers related to "Javascript"

Browse Popular Code Answers by Language