NavigateEvent:destination 屬性
NavigateEvent 介面的只讀屬性 destination 返回一個 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 |
瀏覽器相容性
載入中…