hx-replace-url

hx-replace-url属性允许您替换浏览器位置历史中的当前URL。

该属性的可能值为:

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

示例如下:

<div hx-get="/account" hx-replace-url="true">
  前往我的账户
</div>

这将使htmx将当前DOM快照保存到localStorage,并在浏览器地址栏中替换URL为`/account`。

另一个示例:

<div hx-get="/account" hx-replace-url="/account/home">
  前往我的账户
</div>

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

注意事项