0

I'm developing a SPA with NextJS, and it's made out of exclusively one page. There's not next/link or Router usage whatsoever. The user would visit the page and everything would happen within the DOM, including all button click, view navigations, etc.

The problem that I'm facing right now, is that if the user at any point clicks the back button.. well, they'll leave the site.

I'd love to hear any suggestions that anyone has regarding this.

Mike K
  • 7,621
  • 14
  • 60
  • 120

1 Answers1

0

The beforeunload can help you.

Example:

window.onbeforeunload = function(){
  return ''
}
  • Some error is throw? If the problem is the `window is not defined` see [this question](https://stackoverflow.com/questions/55151041/window-is-not-defined-in-next-js-react-app) – Houston da Paz Aug 26 '20 at 17:47