Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hx-push-url does not include GET parameters #58

Closed
mqudsi opened this issue May 28, 2020 · 3 comments
Closed

hx-push-url does not include GET parameters #58

mqudsi opened this issue May 28, 2020 · 3 comments

Comments

@mqudsi
Copy link

mqudsi commented May 28, 2020

The documentation for hx-push-url starts with

If you want a given element to push its request URL into the browser navigation bar

and this is both the expected behavior and semantically correct when the intended result of the operation is that after the htmx trigger completes, the contents of the current page will be diffed/swapped/manipulated to match the contents of the requested url, but without actually triggering a page load (e.g. purely progressive enhancement).

However, it seems that in reality it is the value of hx-verb that gets pushed to the history/navbar and not the url of the request, as demonstrated by the following:

index.html:

<script src="https://unpkg.com/htmx.org@0.0.4/dist/htmx.min.js"></script>

<div>
	This text is not in the div.
</div>

<div id="target">
	click me
</div>

<input type="checkbox" name="param1" value="foo" hx-get="./contents.html" hx-push-url="true" hx-target="#target" hx-swap="innerHTML" hx-select=".swap" />

contents.html:

<div class="swap">this file contains only the contents of the div</div>

This (correctly) triggers an XHR to /contents.html?param1=foo but the location pushed to the history API is /contents.html rather than the true request URL.

@1cg
Copy link
Contributor

1cg commented May 29, 2020

Yep, looks like a bug. GETs should push the full query URL.

@aiibe
Copy link

aiibe commented May 30, 2020

Some kind of hack but you can set the server response header X-HX-Push to a new url along with the request query params manually. Not ideal but works.

1cg pushed a commit that referenced this issue Jun 10, 2020
@1cg
Copy link
Contributor

1cg commented Jun 10, 2020

Fixed w/ a65c37e

@1cg 1cg closed this as completed Jun 10, 2020
strangeRabbit777 added a commit to strangeRabbit777/high-power-tool that referenced this issue Aug 23, 2022
strangeRabbit777 added a commit to strangeRabbit777/high-power-tool that referenced this issue Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants