I'm building a single-page application using page.js as the router. The default window.onbeforeunload event doesn't seem to fire when changing pages within the SPA. How can I implement something similar, allowing me to selectively cancel the page transition if the user decides not to proceed? (i.e. "your changes are not saved: ok to discard changes?")
Thanks!
To prevent the address bar from changing and effectively stop the page processing, inside the
showfunction, setcontext.handled = false. This stops thepushStateaction within page.js, preventing the address bar from changing.Example: