htmx:before:history:restore
Fires before history restoration
The htmx:before:history:restore event fires when the user navigates back or forward through history (popstate event).
When It Fires
When the browser’s back or forward button is clicked, before content is restored.
Event Detail
-
path- The path being restored -
cacheMiss- Boolean indicating if content needs to be fetched
Example
htmx.on('htmx:before:history:restore', (evt) => {
console.log('Restoring:', evt.detail.path);
if (evt.detail.cacheMiss) {
console.log('Will fetch from server');
}
}); Cancel this event to prevent history restoration and handle it manually.
Licensed under the Zero-Clause BSD License.
https://four.htmx.org/reference/events/htmx-before-restore-history/