From ad62bd3ed2660d0691aeff1ecb11c5997f901a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Sat, 4 Oct 2025 20:07:12 +0200 Subject: fix(frontend): use htmx history instead of custom implementation to have history working --- frontend/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'frontend') diff --git a/frontend/index.ts b/frontend/index.ts index ee1e7ae..9babe4a 100644 --- a/frontend/index.ts +++ b/frontend/index.ts @@ -1,5 +1,7 @@ import htmx from "htmx.org"; +htmx.config.historyRestoreAsHxRequest = false; + function setupAnchors() { document.querySelectorAll("a").forEach(e => { if (!e.href.startsWith(window.location.origin) && /https?:\/\//.test(e.href)) { @@ -17,12 +19,12 @@ function setupAnchors() { // updating history and window title document.addEventListener("htmx:afterSettle", e => { + if (e.detail.xhr === undefined) return const title = e.detail.xhr.getResponseHeader("Updated-Title") if (title?.length !== 0) document.title = title const quote = e.detail.xhr.getResponseHeader("Updated-Quote") if (quote?.length !== 0) document.querySelector("#quote")!.innerHTML = "« " + quote + " »" - window.history.pushState({}, "", e.detail.pathInfo.finalRequestPath) setupAnchors() }) -- cgit v1.2.3