#452·wouter

Prevent "back button" navigation

Author: joecarlCreated May 29, 2024Updated Sep 5, 2026
Labelsfeature

I'm developing an app where I need to prevent "back button" in some cases, (e.g.: when I'm editing a form and I click back button I should receive a confirmation dialog before the navigation occurs).

I tried adding the well known beforeunload event. But it only works when the navigation was not made via pushState/setLocation. Is it possible to achieve the behavior I need with wouter?