Debian Codegraph @

www/src/content/reference/03-events/22-htmx-before-restore-history.md

raw symbols SCIP
1 ---
2 title: "htmx:before:history:restore"
3 description: "Before restoring from history"
4 ---
5
6 The `htmx:before:history:restore` event fires when the user navigates back or forward through history (popstate event).
7
8 ## When It Fires
9
10 When the browser's back or forward button is clicked, before content is restored.
11
12 ## Event Detail
13
14 - `path` - The path being restored
15 - `cacheMiss` - Boolean indicating if content needs to be fetched
16
17 ## Example
18
19 ```javascript
20 htmx.on('htmx:before:history:restore', (evt) => {
21 console.log('Restoring:', evt.detail.path);
22 if (evt.detail.cacheMiss) {
23 console.log('Will fetch from server');
24 }
25 });
26 ```
27
28 Cancel this event to prevent history restoration and handle it manually.