bigskysoftware / bigskysoftware/htmx

Include query parameters when using custom `hx-push-url` value

Open
#2,156 5 comments 6 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

I'm trying to use a custom value for `hx-push-url` (i.e. not `hx-push-url="true"`) and still retain any query parameters (from `hx-get`).

Consider the following example:

```python
from fastapi import FastAPI
from fastapi.responses import HTMLResponse

app = FastAPI()

@app.get("/debug", response_class=HTMLResponse)
def debg(number: int | None = None):
if number:
return f"

Selected {number}

"
return HTMLResponse(
"""


HTMX #653


1
2


"""
)

if __name__ == "__main__":
import uvicorn
uvicorn.run(app)
```

When browsing to `/debug` and selecting `2` in the dropdown it triggers a `"GET /debug?number=2` as expected. However, the URL pushed is just `/debug2` while I would want it to be `/debug2?number=2`. Is that possible?

I have previously replied to the related #653 and don't seem to be the only one interested. There, the answer by @1cg implies this should work, however, as @dcr8898 pointed out the [current code](https://github.com/bigskysoftware/htmx/blob/master/dist/htmx.js#L3419) does not look like it's supposed to.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.