-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Response from HX-Location should respect HX-Push-Url header #3115
Comments
From what I see in the sources: Lines 4692 to 4694 in e0905ff
Lines 4703 to 4705 in e0905ff
I don't see any reason So, I would expect your history to actually contain the URL sent back by your second endpoint's Could you confirm if this is actually what is happening? Do you see the desired URL when going back in the history by 1 step? If so, we can likely add a fix for that |
also see #3045 for more detail on the cause |
The issue is the ajaxHelper function is waits to complete fully as a promise which will push the hx-push-url to history and 'then' it will push the hx-location URL every time. We could add ajaxHelper('get', redirectPath, redirectSwapSpec).then(function() {
if (!redirectSwapSpec?.noPushUrl) pushUrlIntoHistory(redirectPath)
}) to add a new optional key to hx-location data spec that if set true would block the post request push if required. Maybe a better way would be this const oldPath = currentPathForHistory
ajaxHelper('get', redirectPath, redirectSwapSpec).then(function() {
if (oldPath === currentPathForHistory) pushUrlIntoHistory(redirectPath)
}) |
Yes. I can see the desired URL if I go one step back. |
could another solution be to add a pushUrl optional boolean to HtmxAjaxHelperContext and HtmxAjaxEtc and HtmxResponseInfoand then allow ajaxHelper to pass this through with the request config and then set this true for all hx-location requests. Then get the ajax request to push history at the end if this is true by using this boolean in the determineHistoryUpdates function. This new option would also resolve #3114 as there would then be a proper ajax api to push url. |
I have a scenario where I set the
HX-Location
header to redirect the client to other page (assume/x
). In some cases, the response (of/x
) could containHX-Push-Url
header (assume/y
) which is not being respected, i.e., the page url is still same as the url inHX-Location
header (/x
).Is there a way to push the url in
HX-Push-Url
(/y
) header of response in browser history after the redirect usingHX-Location
header?The text was updated successfully, but these errors were encountered: