hx-replace-url

hx-replace-url 属性允许你替换浏览器当前 URL 的 历史记录

此属性的可能值是

  1. true,在浏览器导航栏中替换获取的 URL。
  2. false,如果由于继承会替换获取的 URL,则禁用替换。
  3. 要替换到地址栏中的 URL。可以是相对 URL 或绝对 URL,与 history.replaceState() 相同。

以下是一个示例

<div hx-get="/account" hx-replace-url="true">
  Go to My Account
</div>

这将导致 htmx 将当前 DOM 快照保存到 localStorage 并替换浏览器地址栏中的 URL `/account`。

另一个示例

<div hx-get="/account" hx-replace-url="/account/home">
  Go to My Account
</div>

这将替换浏览器地址栏中的 URL `/account/home`。

注意