NavigationDestination: url 属性
NavigationDestination 接口的只读属性 url 返回正在导航到的 URL。
值
字符串。
示例
使用 intercept() 处理导航
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 # the-navigationdestination-interface:dom-navigationdestination-url-2 |
浏览器兼容性
加载中…