Skip to content

Commit

Permalink
Include full path w/ variables when pushing a GET
Browse files Browse the repository at this point in the history
Fixes #58
  • Loading branch information
carson committed Jun 10, 2020
1 parent 6f14cba commit a65c37e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
}
}

Expand Down
37 changes: 37 additions & 0 deletions test/attributes/hx-push-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}, "<button>Bar</button>");
});
var div = make("<button hx-post='/test' hx-swap='outerHTML'>Foo</button>");
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('<form hx-trigger="click" hx-push-url="true" hx-get="/test"><input type="hidden" name="foo" value="bar"/>first</form>');
form.click();
this.server.respond();
form.textContent.should.equal("second")
path.should.equal("/test?foo=bar")
} finally {
htmx.off("pushedIntoHistory.htmx", handler);
}
});

});

0 comments on commit a65c37e

Please sign in to comment.