hx-history-elt
hx-history-elt
属性允许你指定在导航期间用于快照和恢复页面状态的元素。默认情况下,使用 body
标签。这通常对于大多数设置来说已经足够好了,但你可能希望将其缩小到子元素。只需确保元素在你的应用中始终可见,否则 htmx 将无法正确恢复历史导航。
¥The hx-history-elt
attribute allows you to specify the element that will be used to snapshot and
restore page state during navigation. By default, the body
tag is used. This is typically
good enough for most setups, but you may want to narrow it down to a child element. Just make
sure that the element is always visible in your application, or htmx will not be able to restore
history navigation properly.
这是一个例子:
¥Here is an example:
<html>
<body>
<div id="content" hx-history-elt>
...
</div>
</body>
</html>
¥Notes
hx-history-elt
不是继承的
¥hx-history-elt
is not inherited
在大多数情况下,我们不建议缩小历史快照
¥In most cases we don’t recommend narrowing the history snapshot