Exit Intent
A protection system that detects when users attempt to leave the page and shows confirmation dialogs to prevent accidental navigation.
Preview
Installation
Use the CLI to add this component to your project.
Provider Setup
Basic Usage
Examples
Status Indicator
Display the current protection status. Changes here reflect globally across all components.
Link Protection Controls
Control external link protection. Try enabling/disabling here and see the status update above.
Browser Refresh/Close Controls
Control the browser's native beforeunload warning. When enabled, users see a confirmation when trying to close or refresh the page.
External Links (with dialog)
Standard external links will show a confirmation dialog before navigating away.
Bypassing Confirmation
Use special attributes to bypass the confirmation dialog for trusted links.
Form Protection Pattern
A common pattern: enable protection when user starts editing, disable when they submit successfully.
API Reference
useExitIntent Hook
Props
| Prop | Type | Default | Description |
|---|---|---|---|
isActive | boolean | true | Current state of external link protection |
isBeforeUnloadActive | boolean | true | Current state of browser refresh/close protection |
enableExitIntent | () => void | - | Enable external link protection |
disableExitIntent | () => void | - | Disable external link protection |
temporaryDisable | (duration: number) => void | - | Temporarily disable link protection for specified duration (in ms) |
enableBeforeUnload | () => void | - | Enable browser refresh/close warning |
disableBeforeUnload | () => void | - | Disable browser refresh/close warning |
setBeforeUnloadActive | (active: boolean) => void | - | Set browser warning state directly |
Link Attributes
Props
| Prop | Type | Default | Description |
|---|---|---|---|
data-no-confirm | attribute | - | Add this attribute to any link to bypass the exit confirmation dialog |
target="_blank" | attribute | - | Links opening in new tabs automatically bypass confirmation |
Best Practices
Protect important workflows
Enable both link and browser protection on pages with unsaved changes, forms, or checkout flows.
Use separate controls wisely
You can enable link protection without browser warnings, or vice versa, depending on your UX needs.
Disable after successful actions
Always disable protection after the user has saved their work or completed the workflow.
Use data-no-confirm for trusted links
Add data-no-confirm to trusted external links like documentation or social media.
Global State
Note: All components using useExitIntent share the same global state. When you enable or disable protection from any component, it affects the entire application. This makes it perfect for coordinating protection across different parts of your app.