NavigateEvent:destination 属性
destination
是 NavigateEvent
接口的只读属性,它返回一个 NavigationDestination
对象,该对象表示要导航到的目标。
值
一个 NavigationDestination
对象。
示例
js
navigation.addEventListener("navigate", (event) => {
// Exit early if this navigation shouldn't be intercepted,
// e.g. if the navigation is cross-origin, or a download request
if (shouldNotIntercept(event)) {
return;
}
const url = new URL(event.destination.url);
if (url.pathname.startsWith("/articles/")) {
event.intercept({
async handler() {
// The URL has already changed, so show a placeholder while
// fetching the new content, such as a spinner or loading page
renderArticlePagePlaceholder();
// Fetch the new content and display when ready
const articleContent = await getArticleContent(url.pathname);
renderArticlePage(articleContent);
},
});
}
});
规范
规范 |
---|
HTML 标准 # dom-navigateevent-destination-dev |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。
另请参阅
- 现代客户端路由:导航 API
- 导航 API 说明
- Domenic Denicola 的 导航 API 实时演示