-
Notifications
You must be signed in to change notification settings - Fork 22.9k
Editorial review: Add precommitHandler() and other info to Navigation API docs #41524
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
base: main
Are you sure you want to change the base?
Editorial review: Add precommitHandler() and other info to Navigation API docs #41524
Conversation
Preview URLs
(comment last updated: 2025-10-20 09:52:19) |
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.
Thanks for working on this, see comments
|
||
## Description | ||
|
||
The `intercept()` method is used to implement custom SPA navigation behavior when a navigation occurs, for example when a link is clicked, a form is submitted, or a programmatic navigation is initiated (using {{domxref("History.pushState()")}}, {{domxref("Window.location")}}, etc.). |
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 "SPA navigation behavior" is a bit of an awkward wording, but I'll leave that to the editorial review.
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 changed it to "...implement same-document (SPA) navigation behavior..." for now, but we can iterate on it further if required.
- `history` {{optional_inline}} | ||
- : An enumerated value that specifies how this redirect should be added to the navigation history. It can take one of the following values: | ||
- `auto` | ||
- : The default value, which lets the browser decide how to handle it. Usually the value used is `push`, but it will become `replace` if the redirect points to the same URL as the pre-navigation URL. |
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.
It can also be whatever was passed to navigate()
. The main point of auto
is that the redirect
call doesn't change history handling.
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.
OK, I think I know what you mean here. Is the following correct? (ignore the formatting)
auto
- : The default value, which lets the browser decide how to handle it:
- If the original navigation occurred as a result of a {{domxref("Navigation.navigate()")}} call, the value will be whatever was specified in the
navigate()
call'shistory
option. - Otherwise, the value used is usually
push
, but it will becomereplace
if the redirect points to the same URL as the pre-navigation URL.
- If the original navigation occurred as a result of a {{domxref("Navigation.navigate()")}} call, the value will be whatever was specified in the
- : The default value, which lets the browser decide how to handle it:
|
||
- `state` {{optional_inline}} | ||
- : Contains any state information you want to pass along with the navigation, for example, for logging or tracking purposes. The state for the navigation can subsequently be retrieved via {{domxref("NavigationHistoryEntry.getState()")}}. | ||
- `history` {{optional_inline}} |
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.
Something about this: redirect
can change the behavior between auto/push/replace, but it cannot turn a traverse navigation to a push/replace navigation or vice versa.
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.
Cool; I've added this info as a note at the bottom of the bit about replace()
:
Note
The redirect()
method can can convert the history behavior between auto
, push
, and replace
, but it cannot turn a traverse
navigation into a push
/replace
navigation and vice versa.
Co-authored-by: Noam Rosenthal <[email protected]>
@noamr thanks for the reviews. This one looks about ready to go on to the editorial review stage now, but feel free to add more comments if you think anything else still needs attention. |
Yes, technical LGTM from me! |
Description
Chromium 141 adds support for the
precommitHandler
option of theNavigateEvent.intercept()
method. See https://chromestatus.com/feature/5134734612496384.This PR adds documentation for it.
It also overhauls the
intercept()
method page in general, adding a bunch of details in a large "Description" section that was missing before. I think more work needs to be done here, but it is out of the scope of this PR for me to try to fix everything. For now, I've added a bit more information about how theintercept()
features work so that the page is a bit more informative.Motivation
Additional details
Related issues and pull requests