htmx:before:history:update
Fires before browser history update
The htmx:before:history:update event fires before htmx pushes or replaces a browser history state.
When It Fires
Before history.pushState() or history.replaceState() is called.
Event Detail
-
history- Object withtype(“push” or “replace”) andpath -
sourceElement- Element that triggered the navigation -
response- Response object
Example
htmx.on('htmx:before:history:update', (evt) => {
console.log('Updating history:', evt.detail.history.type, evt.detail.history.path);
// Modify path or cancel history update
}); Cancel this event to prevent the history update.
Licensed under the Zero-Clause BSD License.
https://four.htmx.org/reference/events/htmx-before-history-update/