Skip to content
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
merged 56 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
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 Oct 31, 2022
91e37e2
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 1, 2022
388f304
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 1, 2022
a9ca266
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 1, 2022
0c7dd0d
Merge branch 'main' into add-navigation-api-ref-docs
chrisdavidmills Nov 1, 2022
03a56c7
updating landing page according to domenics comments
chrisdavidmills Nov 1, 2022
6b7a904
remaining interface pages plus assorted fixes
chrisdavidmills Nov 2, 2022
9a2b3ba
add all member pages for Navigate
chrisdavidmills Nov 4, 2022
fad99a3
making fixes for domenic review comments
chrisdavidmills Nov 4, 2022
fc0e240
fix macro error
chrisdavidmills Nov 4, 2022
c8aeb47
Merge branch 'main' into add-navigation-api-ref-docs
Nov 4, 2022
c0ed753
add member pages for NavigationDestination and NavigationHistoryEntry
chrisdavidmills Nov 4, 2022
44c0b18
Merge branch 'add-navigation-api-ref-docs' of github.com:chrisdavidmi…
chrisdavidmills Nov 4, 2022
72f8ce2
attempt to fix folder name casing
chrisdavidmills Nov 4, 2022
b2e1e36
fix casing issue in directory name
chrisdavidmills Nov 7, 2022
4554e97
add all remaining pages, fix flaws
chrisdavidmills Nov 7, 2022
d264c4f
Merge branch 'main' into add-navigation-api-ref-docs
chrisdavidmills Nov 7, 2022
1e96c03
adding description of when disposal occurs
chrisdavidmills Nov 8, 2022
0e18d96
Merge branch 'add-navigation-api-ref-docs' of github.com:chrisdavidmi…
chrisdavidmills Nov 8, 2022
de7f600
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
43f9c1f
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
f3e94db
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
5a47f9e
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
b4a42f3
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
40f93b0
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
dc435da
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
12a51d2
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
33a7e8e
Update files/en-us/web/api/navigation_api/index.md
chrisdavidmills Nov 9, 2022
5938b37
adding fixes for wbamberg comments
chrisdavidmills Nov 9, 2022
ecee4c7
Merge branch 'add-navigation-api-ref-docs' of github.com:chrisdavidmi…
chrisdavidmills Nov 9, 2022
6333b97
adding fixes for wbamberg comments
chrisdavidmills Nov 9, 2022
8725f8e
making fixes for wbamberg comments
chrisdavidmills Nov 10, 2022
03efe1e
Update files/en-us/web/api/navigation/index.md
chrisdavidmills Nov 10, 2022
fa2f482
Update files/en-us/web/api/navigation/updatecurrententry/index.md
chrisdavidmills Nov 10, 2022
3bb1bed
Update files/en-us/web/api/navigation/updatecurrententry/index.md
chrisdavidmills Nov 10, 2022
251848f
Update files/en-us/web/api/navigation/updatecurrententry/index.md
chrisdavidmills Nov 10, 2022
b16a267
Update files/en-us/web/api/navigation/updatecurrententry/index.md
chrisdavidmills Nov 10, 2022
127c770
Update files/en-us/web/api/navigation/traverseto/index.md
chrisdavidmills Nov 10, 2022
3761a1d
Update files/en-us/web/api/navigation/back/index.md
chrisdavidmills Nov 10, 2022
991c81a
Update files/en-us/web/api/navigation/cangoback/index.md
chrisdavidmills Nov 10, 2022
e816cb1
Update files/en-us/web/api/navigation/cangoforward/index.md
chrisdavidmills Nov 10, 2022
9696dbc
Update files/en-us/web/api/navigation/currententry/index.md
chrisdavidmills Nov 10, 2022
504f04f
Update files/en-us/web/api/navigation/forward/index.md
chrisdavidmills Nov 10, 2022
ed352c5
Update files/en-us/web/api/navigation/navigate/index.md
chrisdavidmills Nov 10, 2022
b0a10a5
Update files/en-us/web/api/navigation/navigate/index.md
chrisdavidmills Nov 10, 2022
5e6be2a
Update files/en-us/web/api/navigation/navigate/index.md
chrisdavidmills Nov 10, 2022
4ad513f
Update files/en-us/web/api/navigation/reload/index.md
chrisdavidmills Nov 10, 2022
af10131
Update files/en-us/web/api/navigation/reload/index.md
chrisdavidmills Nov 10, 2022
3b887e3
Update files/en-us/web/api/navigation/transition/index.md
chrisdavidmills Nov 10, 2022
9c9e8da
Update files/en-us/web/api/navigation/traverseto/index.md
chrisdavidmills Nov 10, 2022
d1b7e04
Update files/en-us/web/api/navigation/traverseto/index.md
chrisdavidmills Nov 10, 2022
6448d5b
fixing linter trailing space errors
chrisdavidmills Nov 10, 2022
f4b5752
add structured-clonable information to navigate()
chrisdavidmills Nov 14, 2022
7f81b8b
add structured-clonable information to reload() and updateCurrentEntry()
chrisdavidmills Nov 15, 2022
1476651
making fixes in response to wbamberg navigationhistoryentry comments
chrisdavidmills Nov 16, 2022
1805606
moooooar fixes for wbamberg comments
chrisdavidmills Nov 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions files/en-us/web/api/navigateevent/canintercept/index.md
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).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(e.g. you can't intercept a cross-origin navigation)

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:

Generally speaking, this will be true whenever the current Document can have its URL rewritten to the destination URL, except for cross-document back/forward navigations, where it will always be false.

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:

A navigation can be intercepted in the following circumstances:

  • For http and https URLs, only the path, query, and fragment portions of the new URL may differ from the current URL.
  • For file URLs, only the query and fragment portions of the new URL may differ from the current URL.
  • For all other schemes, only the fragment portion of the new URL may differ from the current URL.

See when a Document can have its URL rewritten.

An exception is for back/forward navigations in which the existing document is replaced with a new one (these are also called cross-document navigations). These navigations can never be intercepted.

?

Copy link
Contributor

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.

Copy link
Collaborator

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".

Copy link
Contributor Author

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.


## 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/)
71 changes: 71 additions & 0 deletions files/en-us/web/api/navigateevent/destination/index.md
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 files/en-us/web/api/navigateevent/downloadrequest/index.md
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/)
70 changes: 70 additions & 0 deletions files/en-us/web/api/navigateevent/formdata/index.md
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{domxref("NavigateEvent")}} interface returns the {{domxref("FormData")}} object representing the submitted data in the case of a `POST` form submission, or `null` otherwise.
{{domxref("NavigateEvent")}} interface returns the {{domxref("FormData")}} object representing the submitted data in the case of a [`POST`](/en-US/docs/Web/HTTP/Methods/POST) form submission, or `null` otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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/)
70 changes: 70 additions & 0 deletions files/en-us/web/api/navigateevent/hashchange/index.md
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/)
Loading