NavigationDestination:key 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

NavigationDestination 接口的 key 只读属性在 NavigateEvent.navigationTypetraverse 时返回目标 NavigationHistoryEntrykey 值,否则返回空字符串。

key 是一个唯一的、由 UA 生成的值,表示历史条目在历史条目列表中的位置,用于通过 Navigation.traverseTo() 导航到历史记录中的此位置。它将被替换列表中条目的其他条目重用(即,如果 NavigateEvent.navigationTypereplace)。

表示目标 NavigationHistoryEntrykey 的字符串,或者一个空字符串。

示例

js
navigation.addEventListener("navigate", (event) => {
  console.log(event.destination.key);
});

规范

Specification
HTML
# the-navigationdestination-interface:dom-navigationdestination-key-2

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
key
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

参见