add prenav hook

This commit is contained in:
Jacky Zhao
2025-03-09 09:04:04 -07:00
parent 26ff78f81f
commit 50efa14bd2
5 changed files with 28 additions and 2 deletions

View File

@@ -161,6 +161,15 @@ document.addEventListener("nav", () => {
})
```
You can also add the equivalent of a `beforeunload` event for [[SPA Routing]] via the `prenav` event.
```ts
document.addEventListener("prenav", () => {
// executed after an SPA navigation is triggered but
// before the page is replaced
})
```
It is best practice to track any event handlers via `window.addCleanup` to prevent memory leaks.
This will get called on page navigation.