next-page-router-back-navigation-guard Example
Note: This is the entry page. Back button handling does not work here because there is no forward history to restore. Navigate to any test page first, then press back to see the handler in action.
Test Scenarios:
- Basic Handler — Show confirm dialog, block on cancel, allow on confirm
- Once Option — Handler executes once then auto-unregisters
- Enable Option — Conditionally enable/disable handler
- Override Handlers — Multiple handlers with priority (lower runs first)
- Priority Order — Non-override handlers with priority ordering
- Pre-registered Handler — Global handler via Provider prop (e.g., close modals)
- No Handler — Page without handler (normal back navigation)
- Safe Redirect Pattern — Block back, show modal, redirect on confirm (recommended)
Known Limitations:
- Redirect on Back (NOT SUPPORTED) — router.push() inside handler causes unpredictable behavior
- Entry page (this page) cannot block back — no forward history to restore