Navigation:currentEntry 属性

Limited availability

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

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

Navigation 接口的 currentEntry 只读属性返回一个 NavigationHistoryEntry 对象,表示用户当前导航到的历史记录。

一个 NavigationHistoryEntry 对象。

示例

js
function initHomeBtn() {
  // 获取第一个加载条目的键,以便用户可以随时返回该视图。
  const { key } = navigation.currentEntry;
  backToHomeButton.onclick = () => {
    navigation.traverseTo(key);
  };
}
// 拦截导航事件(例如链接点击),并将其替换为单页导航
navigation.addEventListener("navigate", (event) => {
  event.intercept({
    async handler() {
      // 导航到不同的视图,但“主页”按钮始终有效。
    },
  });
});

规范

Specification
HTML
# dom-navigation-currententry-dev

浏览器兼容性

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
currentEntry
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.

参见