hx-replace-url
The hx-replace-url
attribute allows you to replace the current url of the browser location history.
The possible values of this attribute are:
true
, which replaces the fetched URL in the browser navigation bar.false
, which disables replacing the fetched URL if it would otherwise be replaced due to inheritance.history.replaceState()
.Here is an example:
<div hx-get="/account" hx-replace-url="true">
Go to My Account
</div>
This will cause htmx to snapshot the current DOM to localStorage
and replace the URL `/account’ in the browser location bar.
Another example:
<div hx-get="/account" hx-replace-url="/account/home">
Go to My Account
</div>
This will replace the URL `/account/home’ in the browser location bar.
hx-replace-url
is inherited and can be placed on a parent elementHX-Replace-Url
response header has similar behavior and can override this attribute.hx-history-elt
attribute allows changing which element is saved in the history cache.hx-push-url
attribute is a similar and more commonly used attribute, which creates a
new history entry rather than replacing the current one.