Created
October 26, 2022 09:55
-
-
Save croxton/e9c8dc777c9e334c213af280e41fbb8b to your computer and use it in GitHub Desktop.
htmx push history
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//=========================================== | |
// Create a new history entry for the request | |
//=========================================== | |
var pushUrl = getClosestAttributeValue(elt, "hx-push-url"); | |
var elementIsBoosted = getInternalData(elt).boosted; | |
if (pushUrl || elementIsBoosted) { | |
// If hx-push-url is explicitly defined (and not "true" or "false"), | |
// we already know what the final URL should be. | |
// For boosted elements the final URL will be the same as the request path. | |
if (elementIsBoosted || pushUrl === "true" || pushUrl === "false") { | |
// Fallback to path | |
pushUrl = path; | |
} | |
if (pushUrl === null || finalPathForGet) { | |
// Otherwise use the current url to create a new history | |
// entry *without* changing the location url. | |
// The response will change (replaceState) the final URL | |
pushUrl = currentPathForHistory; | |
} | |
// Create a history entry | |
pushUrlIntoHistory(pushUrl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment