Overview
Two tools cover leave guards: lockNavigation() for a silent hard block, and onNavigationRequest(fn) for confirm-to-leave. Prefer the request hook when you need a dialog.
With any onNavigationRequest subscriber, navigateTo never auto-commits. Every subscriber must call next() (AND). Prefer onNavigate for post-commit side effects.
lock vs request
|
API
|
Use when
|
Commit model
|
|---|---|---|
lockNavigation()
| Silent hard block |
navigateTo no-ops; beforeunload on tab close.
|
onNavigationRequest(fn)
| Confirm dialog |
Call next() to allow, omit to cancel.
|
onNavigate
| After commit | Analytics / scroll — not a guard. |
Unsaved text box — ConfirmDialog
Type in the text box to mark the form dirty. navigateTo then opens a mates-ui ConfirmDialog; Leave calls next(), Stay cancels.
onNavigationRequest confirm (simulated)
Sandbox cannot show window.confirm reliably — toggle allow to simulate next() vs cancel.