From a65c37ec4f586ebf6406416f3158419f21c1a7c6 Mon Sep 17 00:00:00 2001 From: carson Date: Wed, 10 Jun 2020 16:37:03 -0700 Subject: [PATCH] Include full path w/ variables when pushing a GET Fixes https://github.com/bigskysoftware/htmx/issues/58 --- src/htmx.js | 4 +++- test/attributes/hx-push-url.js | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/htmx.js b/src/htmx.js index a7ea72db..4eca8668 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -1447,7 +1447,9 @@ return (function () { }); // push URL and save new page if (shouldSaveHistory) { - pushUrlIntoHistory(pushedUrl || path); + var pathToPush = pushedUrl || finalPathForGet || path; + pushUrlIntoHistory(pathToPush); + triggerEvent(getDocument().body, 'pushedIntoHistory.htmx', {path:pathToPush}); } } diff --git a/test/attributes/hx-push-url.js b/test/attributes/hx-push-url.js index 4559d57a..efb91b02 100644 --- a/test/attributes/hx-push-url.js +++ b/test/attributes/hx-push-url.js @@ -131,4 +131,41 @@ describe("hx-push-url attribute", function() { cache.length.should.equal(1); }); + it("afterSettle.htmx is called when replacing outerHTML", function () { + var called = false; + var handler = htmx.on("afterSettle.htmx", function (evt) { + called = true; + }); + try { + this.server.respondWith("POST", "/test", function (xhr) { + xhr.respond(200, {}, ""); + }); + var div = make(""); + div.click(); + this.server.respond(); + should.equal(called, true); + } finally { + htmx.off("afterSettle.htmx", handler); + } + }); + + it("should include parameters on a get", function () { + var path = ""; + var handler = htmx.on("pushedIntoHistory.htmx", function (evt) { + path = evt.detail.path; + }); + try { + this.server.respondWith("GET", /test.*/, function (xhr) { + xhr.respond(200, {}, "second") + }); + var form = make('
first
'); + form.click(); + this.server.respond(); + form.textContent.should.equal("second") + path.should.equal("/test?foo=bar") + } finally { + htmx.off("pushedIntoHistory.htmx", handler); + } + }); + }); \ No newline at end of file