You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Open prevent page leave modal on browser back button navigation
Implemented a workaround to show the "prevent leave" modal when users
click the browser back button with unsaved changes. This solution
addresses a limitation in Next.js App Router which doesn't provide
built-in hooks for intercepting browser history navigation events.
Technical details:
- Creates a duplicate history entry as a buffer to prevent immediate
back navigation, allowing the prevent leave modal to be displayed.
- Uses history.go(-2) to properly navigate when user confirms leaving
- Re-establishes buffer state when user cancels navigation
Note: This implementation specifically targets the browser back button
use case, which covers the vast majority of user navigation patterns.
Forward button navigation is not supported by this workaround, but I
think this is an acceptable trade-off considering the complexity of
fully emulating the browser's history behavior within a Next.js
application.
0 commit comments