Debian Codegraph @

www/src/content/reference/03-events/18-htmx-before-history-update.md

raw symbols SCIP
1 ---
2 title: "htmx:before:history:update"
3 description: "Before browser history is updated"
4 ---
5
6 The `htmx:before:history:update` event fires before htmx pushes or replaces a browser history state.
7
8 ## When It Fires
9
10 Before `history.pushState()` or `history.replaceState()` is called.
11
12 ## Event Detail
13
14 - `history` - Object with `type` ("push" or "replace") and `path`
15 - `sourceElement` - Element that triggered the navigation
16 - `response` - Response object
17
18 ## Example
19
20 ```javascript
21 htmx.on('htmx:before:history:update', (evt) => {
22 console.log('Updating history:', evt.detail.history.type, evt.detail.history.path);
23 // Modify path or cancel history update
24 });
25 ```
26
27 Cancel this event to prevent the history update.