bigskysoftware / bigskysoftware/htmx
HX-Location feature: push url options (example of working code, tiny change)
- Dominant language
- JavaScript
- Stars
- 49.4k
- Forks
- 1.7k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 30
Description
Currently HX-Location auto pushes the url to history (expected _default_ behaviour).
```JavaScript
if (hasHeader(xhr, /HX-Location:/i)) {
saveCurrentPageToHistory()
let redirectPath = xhr.getResponseHeader('HX-Location')
/** @type {HtmxAjaxHelperContext&{path:string}} */
var redirectSwapSpec
if (redirectPath.indexOf('{') === 0) {
redirectSwapSpec = parseJSON(redirectPath)
// what's the best way to throw an error if the user didn't include this
redirectPath = redirectSwapSpec.path
delete redirectSwapSpec.path
}
ajaxHelper('get', redirectPath, redirectSwapSpec).then(function() {
pushUrlIntoHistory(redirectPath)
})
return
}
```
If possible could we gain some control over `pushUrlIntoHistory(redirectPath)` specifically gain the ability to set to 'false' or a custom location?
An alternative would be to let HX-Replace-Url response header work with it; currently it does not seem to fire after this swap so does not work in this instance.
HX-Trigger works with HX-Location (which is why I was using it) as I want to send custom trigger events with the redirect but I want to specify the url pushed or have none at all, this might _not_ be intended behaviour (a bug). HX-Trigger does not work with standard Location response header or I would have just used that.
Sorry if this is a dumb request (there was a simple solution to my issue in Django). But it strikes me that this functionality could be useful to more people than just my edge case here. The HX-Location is described as doing a client side redirect _**without**_ a full page reload. As such the push url seems to be something we might want more control over.
Disregard if I am just an Eedjit.
Wook.
Contributor guide
Assessment
This issue has not been assessed yet.