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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
updating landing page according to domenics comments
chrisdavidmills committed Nov 1, 2022
commit 03a56c76a2eaa211efa759d692d5f7b44f4610f4
15 changes: 7 additions & 8 deletions files/en-us/web/api/navigation_api/index.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ browser-compat:
- api.Window.navigation
---

{{securecontext_header}}{{seecompattable}}{{DefaultAPISidebar("Navigation API")}}
{{seecompattable}}{{DefaultAPISidebar("Navigation API")}}

The **Navigation API** provides the ability to initiate, intercept, and manage browser navigation actions. It can also introspect an application's history entries. This is a successor to previous web platform features such as [The History API](/en-US/docs/Web/API/History_API) and {{domxref("window.location")}}, which solves their shortcomings and is specifically aimed at the needs of {{glossary("SPA", "single-page applications (SPAs)")}}.

@@ -41,7 +41,7 @@ Once a navigation is initiated, and your `intercept()` handler is called, a {{do

> **Note:** In this context "transition" refers to the transition between one history entry and another. It isn't related to CSS transitions.
> **Note:** You can also call {{domxref("Event.preventDefault", "preventDefault()")}} to stop the navigation entirely.
> **Note:** In future implementations you will be able to call {{domxref("Event.preventDefault", "preventDefault()")}} to stop the navigation entirely. This is specced out, but not currently implemented anywhere.
When the `intercept()` handler function's promise fulfills, the `Navigate` object's {{domxref("Navigation/navigatesuccess_event", "navigatesuccess")}} event fires, allowing you to run cleanup code after a successful navigation has completed. If it rejects, meaning the navigation has failed, {{domxref("Navigation/navigateerror_event", "navigateerror")}} fires instead, allowing you to gracefully handle the failure case. There is also a {{domxref("NavigationTransition.finished", "finished")}} property on the `NavigationTransition` object, which fullfills or rejects at the same time as the aforementioned events are fired, providing another path for handling the success and failure cases if it is needed.

@@ -69,15 +69,13 @@ The Navigation API allows you to store state on each history entry. This is deve

To get a {{domxref("NavigationHistoryEntry")}}'s state, you call its {{domxref("NavigationHistoryEntry.getState", "getState()")}} method. It is initially `undefined`, but when state information is set on the entry, it will return the previously-set state information.

Setting state is a bit more nuanced. You can't retrieve the state value and then update it directly — the copy stored on the entry will not change. Instead, you need to update it while performing a {{domxref("Navigation.navigate", "navigate()")}} or {{domxref("Navigation.reload", "reload()")}} — each one of these optionally takes an options object parameter, which includes a `state` property containing the new state to set on the history entry. When these navigations commit, the state change will be automatically applied.
Setting state is a bit more nuanced. You can't retrieve the state value and then update it directly — the copy stored on the entry will not change. Instead, you update it while performing a {{domxref("Navigation.navigate", "navigate()")}} or {{domxref("Navigation.reload", "reload()")}} — each one of these optionally takes an options object parameter, which includes a `state` property containing the new state to set on the history entry. When these navigations commit, the state change will be automatically applied.

In other cases a state change is not automatically applied, and you will need to do it manually once the navigation has completed. This is handled using {{domxref("Navigation.updateCurrentEntry", "updateCurrentEntry()")}}. The {{domxref("Navigation/currententrychange_event", "currententrychange")}} will fire when the current entry change is complete.

(I'M REALLY NOT SURE IF THIS SECTION ON STATE IS ACCURATE. I AM KINDA GUESSING AT THE "AUTOMATIC BEHAVIOR" MENTIONED ABOVE, AND WHEN UPDATECURRENTENTRY() SHOULD BE USED. NONE OF THE MATERIAL I'VE FOUND SEEMS PARTICULARLY CLEAR ON THIS POINT.)
In some cases however, a state change will be independent from a navigation or reload — for example when a page contains an expandable/collapsible {{htmlelement("details")}} element. In this case, you might want to store the expanded/collapsed state in your history entry, so you can restore it when the user returns to the page or restarts their browser. Cases like this are handled using {{domxref("Navigation.updateCurrentEntry", "updateCurrentEntry()")}}. The {{domxref("Navigation/currententrychange_event", "currententrychange")}} will fire when the current entry change is complete.

### Limitations

There are a few perceived limitations with the Navigation API, which may or may not be limitating depending on how your app is set up. Find out about these by reading [Modern client-side routing: the Navigation API > What's missing?](https://developer.chrome.com/docs/web-platform/navigation-api/#whats-missing)
There are a few perceived limitations with the Navigation API, which may or may not be limiting depending on how your app is set up. Find out about these by reading [Modern client-side routing: the Navigation API > What's missing?](https://developer.chrome.com/docs/web-platform/navigation-api/#whats-missing)

## Interfaces

@@ -175,7 +173,7 @@ Or
navigation.reload({state: newState});
```

Or if the state could not be updated automatically during a navigation transition:
Or if the state is independent from a navigation or reload:

```js
navigation.updateCurrentEntry({state: newState});
@@ -192,3 +190,4 @@ navigation.updateCurrentEntry({state: newState});
## 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)