NavigateEvent:destination 属性
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
NavigateEvent
接口的 destination
只读属性返回一个 NavigationDestination
对象,表示要导航到的目标。
值
示例
js
navigation.addEventListener("navigate", (event) => {
// 如果此导航不应被拦截,则提前退出,例如,如果导航是跨源的,或者是下载请求
if (shouldNotIntercept(event)) {
return;
}
const url = new URL(event.destination.url);
if (url.pathname.startsWith("/articles/")) {
event.intercept({
async handler() {
// URL 已更改,因此在获取新内容时显示占位符,例如旋转图标或加载页面
renderArticlePagePlaceholder();
// 获取新内容并在准备就绪时显示
const articleContent = await getArticleContent(url.pathname);
renderArticlePage(articleContent);
},
});
}
});
规范
Specification |
---|
HTML # dom-navigateevent-destination-dev |
浏览器兼容性
BCD tables only load in the browser
参见
- 现代客户端路由:导航 API
- 导航 API 说明
- Domenic Denicola 的导航 API 在线演示