-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Currently HX-Location auto pushes the url to history (expected default behaviour).
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.