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 all 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
79 changes: 79 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,79 @@
---
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 and have its URL rewritten, or `false` otherwise

There are several rules around when a navigation can be intercepted. For example:

- You can't intercept cross-origin navigations.
- You can intercept `http` or `https` URLs if only the `path`, `query`, and `fragment` portions of the new URL differ from the current URL.
- You can intercept `file` URLs if only the `query` and `fragment` portions of the new URL differ.
- For other URL types you can intercept the navigation if only the `fragment` portion differs.

See the spec for more explanation on [when a Document can have its URL rewritten](https://html.spec.whatwg.org/multipage/nav-history-apis.html#can-have-its-url-rewritten), including a table of examples.

## 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`](/en-US/docs/Web/HTTP/Methods/POST) form submission, or `null` otherwise.

## 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