-
Notifications
You must be signed in to change notification settings - Fork 22.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add docs for the Navigation API #21960
Merged
wbamberg
merged 56 commits into
mdn:main
from
chrisdavidmills:add-navigation-api-ref-docs
Nov 20, 2022
Merged
Changes from 54 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
f74c58c
add docs for the Navigation API
chrisdavidmills 91e37e2
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills 388f304
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills a9ca266
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills 0c7dd0d
Merge branch 'main' into add-navigation-api-ref-docs
chrisdavidmills 03a56c7
updating landing page according to domenics comments
chrisdavidmills 6b7a904
remaining interface pages plus assorted fixes
chrisdavidmills 9a2b3ba
add all member pages for Navigate
chrisdavidmills fad99a3
making fixes for domenic review comments
chrisdavidmills fc0e240
fix macro error
chrisdavidmills c8aeb47
Merge branch 'main' into add-navigation-api-ref-docs
c0ed753
add member pages for NavigationDestination and NavigationHistoryEntry
chrisdavidmills 44c0b18
Merge branch 'add-navigation-api-ref-docs' of github.com:chrisdavidmi…
chrisdavidmills 72f8ce2
attempt to fix folder name casing
chrisdavidmills b2e1e36
fix casing issue in directory name
chrisdavidmills 4554e97
add all remaining pages, fix flaws
chrisdavidmills d264c4f
Merge branch 'main' into add-navigation-api-ref-docs
chrisdavidmills 1e96c03
adding description of when disposal occurs
chrisdavidmills 0e18d96
Merge branch 'add-navigation-api-ref-docs' of github.com:chrisdavidmi…
chrisdavidmills de7f600
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills 43f9c1f
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills f3e94db
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills 5a47f9e
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills b4a42f3
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills 40f93b0
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills dc435da
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills 12a51d2
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills 33a7e8e
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills 5938b37
adding fixes for wbamberg comments
chrisdavidmills ecee4c7
Merge branch 'add-navigation-api-ref-docs' of github.com:chrisdavidmi…
chrisdavidmills 6333b97
adding fixes for wbamberg comments
chrisdavidmills 8725f8e
making fixes for wbamberg comments
chrisdavidmills 03efe1e
Update files/en-us/web/api/navigation/index.md
chrisdavidmills fa2f482
Update files/en-us/web/api/navigation/updatecurrententry/index.md
chrisdavidmills 3bb1bed
Update files/en-us/web/api/navigation/updatecurrententry/index.md
chrisdavidmills 251848f
Update files/en-us/web/api/navigation/updatecurrententry/index.md
chrisdavidmills b16a267
Update files/en-us/web/api/navigation/updatecurrententry/index.md
chrisdavidmills 127c770
Update files/en-us/web/api/navigation/traverseto/index.md
chrisdavidmills 3761a1d
Update files/en-us/web/api/navigation/back/index.md
chrisdavidmills 991c81a
Update files/en-us/web/api/navigation/cangoback/index.md
chrisdavidmills e816cb1
Update files/en-us/web/api/navigation/cangoforward/index.md
chrisdavidmills 9696dbc
Update files/en-us/web/api/navigation/currententry/index.md
chrisdavidmills 504f04f
Update files/en-us/web/api/navigation/forward/index.md
chrisdavidmills ed352c5
Update files/en-us/web/api/navigation/navigate/index.md
chrisdavidmills b0a10a5
Update files/en-us/web/api/navigation/navigate/index.md
chrisdavidmills 5e6be2a
Update files/en-us/web/api/navigation/navigate/index.md
chrisdavidmills 4ad513f
Update files/en-us/web/api/navigation/reload/index.md
chrisdavidmills af10131
Update files/en-us/web/api/navigation/reload/index.md
chrisdavidmills 3b887e3
Update files/en-us/web/api/navigation/transition/index.md
chrisdavidmills 9c9e8da
Update files/en-us/web/api/navigation/traverseto/index.md
chrisdavidmills d1b7e04
Update files/en-us/web/api/navigation/traverseto/index.md
chrisdavidmills 6448d5b
fixing linter trailing space errors
chrisdavidmills f4b5752
add structured-clonable information to navigate()
chrisdavidmills 7f81b8b
add structured-clonable information to reload() and updateCurrentEntry()
chrisdavidmills 1476651
making fixes in response to wbamberg navigationhistoryentry comments
chrisdavidmills 1805606
moooooar fixes for wbamberg comments
chrisdavidmills File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: NavigateEvent.canIntercept | ||
slug: Web/API/NavigateEvent/canIntercept | ||
page-type: web-api-instance-property | ||
tags: | ||
- API | ||
- canIntercept | ||
- Experimental | ||
- History | ||
- Navigate | ||
- NavigateEvent | ||
- Navigation | ||
- Navigation API | ||
- Property | ||
- Read-only | ||
- Reference | ||
- Scroll | ||
- Traversal | ||
browser-compat: api.NavigateEvent.canIntercept | ||
--- | ||
|
||
{{APIRef("Navigation API")}}{{seecompattable}} | ||
|
||
The **`canIntercept`** read-only property of the | ||
{{domxref("NavigateEvent")}} interface returns `true` if the navigation can be intercepted, or `false` otherwise (e.g. you can't intercept a cross-origin navigation). | ||
|
||
## Value | ||
|
||
A boolean value—`true` if the navigation can be intercepted, `false` if not. | ||
|
||
## Examples | ||
|
||
```js | ||
navigation.addEventListener("navigate", event => { | ||
// Some navigations, e.g. cross-origin navigations, we | ||
// cannot intercept. Let the browser handle those normally. | ||
if (!event.canIntercept) { | ||
return; | ||
} | ||
|
||
// Don't intercept fragment navigations or downloads. | ||
if (event.hashChange || event.downloadRequest !== null) { | ||
return; | ||
} | ||
|
||
event.intercept({ | ||
handler() { | ||
if (event.formData) { | ||
processFormDataAndUpdateUI(event.formData, event.signal); | ||
} else { | ||
doSinglePageAppNav(event.destination, event.signal); | ||
} | ||
} | ||
}); | ||
}); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Modern client-side routing: the Navigation API](https://developer.chrome.com/docs/web-platform/navigation-api/) | ||
- [Navigation API explainer](https://github.com/WICG/navigation-api/blob/main/README.md) | ||
- Domenic Denicola's [Navigation API live demo](https://gigantic-honored-octagon.glitch.me/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
title: NavigateEvent.destination | ||
slug: Web/API/NavigateEvent/destination | ||
page-type: web-api-instance-property | ||
tags: | ||
- API | ||
- destination | ||
- Experimental | ||
- History | ||
- Navigate | ||
- NavigateEvent | ||
- Navigation | ||
- Navigation API | ||
- Property | ||
- Read-only | ||
- Reference | ||
- Scroll | ||
- Traversal | ||
browser-compat: api.NavigateEvent.destination | ||
--- | ||
|
||
{{APIRef("Navigation API")}}{{seecompattable}} | ||
|
||
The **`destination`** read-only property of the | ||
{{domxref("NavigateEvent")}} interface returns a {{domxref("NavigationDestination")}} object representing the destination being navigated to. | ||
|
||
## Value | ||
|
||
A {{domxref("NavigationDestination")}} object. | ||
|
||
## Examples | ||
|
||
```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); | ||
}, | ||
}); | ||
} | ||
}); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Modern client-side routing: the Navigation API](https://developer.chrome.com/docs/web-platform/navigation-api/) | ||
- [Navigation API explainer](https://github.com/WICG/navigation-api/blob/main/README.md) | ||
- Domenic Denicola's [Navigation API live demo](https://gigantic-honored-octagon.glitch.me/) |
70 changes: 70 additions & 0 deletions
70
files/en-us/web/api/navigateevent/downloadrequest/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: NavigateEvent.downloadRequest | ||
slug: Web/API/NavigateEvent/downloadRequest | ||
page-type: web-api-instance-property | ||
tags: | ||
- API | ||
- downloadRequest | ||
- Experimental | ||
- History | ||
- Navigate | ||
- NavigateEvent | ||
- Navigation | ||
- Navigation API | ||
- Property | ||
- Read-only | ||
- Reference | ||
- Scroll | ||
- Traversal | ||
browser-compat: api.NavigateEvent.downloadRequest | ||
--- | ||
|
||
{{APIRef("Navigation API")}}{{seecompattable}} | ||
|
||
The **`downloadRequest`** read-only property of the | ||
{{domxref("NavigateEvent")}} interface returns the filename of the file requested for download, in the case of a download navigation (e.g. an {{htmlelement("a")}} or {{htmlelement("area")}} element with a `download` attribute), or `null` otherwise. | ||
|
||
## Value | ||
|
||
A string containing the filename of the file requested for download, or `null`. | ||
|
||
## Examples | ||
|
||
```js | ||
navigation.addEventListener("navigate", (event) => { | ||
// Some navigations, e.g. cross-origin navigations, we | ||
// cannot intercept. Let the browser handle those normally. | ||
if (!event.canIntercept) { | ||
return; | ||
} | ||
|
||
// Don't intercept fragment navigations or downloads. | ||
if (event.hashChange || event.downloadRequest !== null) { | ||
return; | ||
} | ||
|
||
event.intercept({ | ||
handler() { | ||
if (event.formData) { | ||
processFormDataAndUpdateUI(event.formData, event.signal); | ||
} else { | ||
doSinglePageAppNav(event.destination, event.signal); | ||
} | ||
} | ||
}); | ||
}); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Modern client-side routing: the Navigation API](https://developer.chrome.com/docs/web-platform/navigation-api/) | ||
- [Navigation API explainer](https://github.com/WICG/navigation-api/blob/main/README.md) | ||
- Domenic Denicola's [Navigation API live demo](https://gigantic-honored-octagon.glitch.me/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,70 @@ | ||||||
--- | ||||||
title: NavigateEvent.formData | ||||||
slug: Web/API/NavigateEvent/formData | ||||||
page-type: web-api-instance-property | ||||||
tags: | ||||||
- API | ||||||
- Experimental | ||||||
- formData | ||||||
- History | ||||||
- Navigate | ||||||
- NavigateEvent | ||||||
- Navigation | ||||||
- Navigation API | ||||||
- Property | ||||||
- Read-only | ||||||
- Reference | ||||||
- Scroll | ||||||
- Traversal | ||||||
browser-compat: api.NavigateEvent.formData | ||||||
--- | ||||||
|
||||||
{{APIRef("Navigation API")}}{{seecompattable}} | ||||||
|
||||||
The **`formData`** read-only property of the | ||||||
{{domxref("NavigateEvent")}} interface returns the {{domxref("FormData")}} object representing the submitted data in the case of a `POST` form submission, or `null` otherwise. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks; I've updated this. |
||||||
|
||||||
## Value | ||||||
|
||||||
A {{domxref("FormData")}} object, or `null`. | ||||||
|
||||||
## Examples | ||||||
|
||||||
```js | ||||||
navigation.addEventListener("navigate", (event) => { | ||||||
// Some navigations, e.g. cross-origin navigations, we | ||||||
// cannot intercept. Let the browser handle those normally. | ||||||
if (!event.canIntercept) { | ||||||
return; | ||||||
} | ||||||
|
||||||
// Don't intercept fragment navigations or downloads. | ||||||
if (event.hashChange || event.downloadRequest !== null) { | ||||||
return; | ||||||
} | ||||||
|
||||||
event.intercept({ | ||||||
handler() { | ||||||
if (event.formData) { | ||||||
processFormDataAndUpdateUI(event.formData, event.signal); | ||||||
} else { | ||||||
doSinglePageAppNav(event.destination, event.signal); | ||||||
} | ||||||
} | ||||||
}); | ||||||
}); | ||||||
``` | ||||||
|
||||||
## Specifications | ||||||
|
||||||
{{Specifications}} | ||||||
|
||||||
## Browser compatibility | ||||||
|
||||||
{{Compat}} | ||||||
|
||||||
## See also | ||||||
|
||||||
- [Modern client-side routing: the Navigation API](https://developer.chrome.com/docs/web-platform/navigation-api/) | ||||||
- [Navigation API explainer](https://github.com/WICG/navigation-api/blob/main/README.md) | ||||||
- Domenic Denicola's [Navigation API live demo](https://gigantic-honored-octagon.glitch.me/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: NavigateEvent.hashChange | ||
slug: Web/API/NavigateEvent/hashChange | ||
page-type: web-api-instance-property | ||
tags: | ||
- API | ||
- Experimental | ||
- hashChange | ||
- History | ||
- Navigate | ||
- NavigateEvent | ||
- Navigation | ||
- Navigation API | ||
- Property | ||
- Read-only | ||
- Reference | ||
- Scroll | ||
- Traversal | ||
browser-compat: api.NavigateEvent.hashChange | ||
--- | ||
|
||
{{APIRef("Navigation API")}}{{seecompattable}} | ||
|
||
The **`hashChange`** read-only property of the | ||
{{domxref("NavigateEvent")}} interface returns `true` if the navigation is a fragment navigation (i.e. to a fragment identifier in the same document), or `false` otherwise. | ||
|
||
## Value | ||
|
||
A boolean value—`true` if the navigation is a fragment navigation, `false` if not. | ||
|
||
## Examples | ||
|
||
```js | ||
navigation.addEventListener("navigate", (event) => { | ||
// Some navigations, e.g. cross-origin navigations, we | ||
// cannot intercept. Let the browser handle those normally. | ||
if (!event.canIntercept) { | ||
return; | ||
} | ||
|
||
// Don't intercept fragment navigations or downloads. | ||
if (event.hashChange || event.downloadRequest !== null) { | ||
return; | ||
} | ||
|
||
event.intercept({ | ||
handler() { | ||
if (event.formData) { | ||
processFormDataAndUpdateUI(event.formData, event.signal); | ||
} else { | ||
doSinglePageAppNav(event.destination, event.signal); | ||
} | ||
} | ||
}); | ||
}); | ||
``` | ||
|
||
## Specifications | ||
|
||
{{Specifications}} | ||
|
||
## Browser compatibility | ||
|
||
{{Compat}} | ||
|
||
## See also | ||
|
||
- [Modern client-side routing: the Navigation API](https://developer.chrome.com/docs/web-platform/navigation-api/) | ||
- [Navigation API explainer](https://github.com/WICG/navigation-api/blob/main/README.md) | ||
- Domenic Denicola's [Navigation API live demo](https://gigantic-honored-octagon.glitch.me/) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be helpful to explain this a little more. Whenever I see an explanation that's only "e.g." I think, well this is an example, but what are the other cases?
The spec says:
I don't like "Generally speaking" there, but at least "can have its URL rewritten" seems to have a clear definition: https://html.spec.whatwg.org/multipage/nav-history-apis.html#can-have-its-url-rewritten. For "except for cross-document back/forward navigations, where it will always be false" I did find this on cross-document navigation: https://chromium.googlesource.com/chromium/src/+/main/docs/navigation_concepts.md#same_document-and-cross_document-navigations , which is presented as a Chromium thing but that seems comprehensible.
So could we say something like:
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The full explanation for this case goes beyond this, and requires reading the whole table at https://github.com/wicg/navigation-api#appendix-types-of-navigations . That's why the non-normative (for web developers) part of the spec uses the vague phrase "generally speaking", because it's too complex to summarize quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW As a reader the normative information is what I want first; a general summary that will apply for most circumstances - because most of the time I'm reading for the gist.
But I would absolutely also want more precision on the most common cases as @wbamberg has done for http, https and file. If it can't be cannonical as a list, I'd note that "there are a number of other cases listed in the specification, covering X, Y, Z".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rewritten this to provide some examples, using some of Will's text, but I've also linked out to the spec for full information. This is one of those cases in which I don't think it's worth trying to repeat the full explanation on MDN. I think most web devs won't need it.