Navigation:currentEntry 属性
Baseline
2026
Newly available
Since January 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or 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> |
浏览器兼容性
参见
- 现代客户端路由:导航 API
- 导航 API 说明
- Domenic Denicola 的导航 API 在线演示