Skip to content
Merged
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,15 @@ Because precommit handlers can be used to cancel the navigation before the URL u

#### Redirects during deferred commit

The `precommitHandler` callback accepts an argument, which is a `controller` that can perform certain actions on the precommitted navigation, in particular redirecting. This updates the eventual destination of the `"push"` or `"replace"` navigation. An example usage is as follows
The `precommitHandler` callback accepts an argument, which is a `controller` that can perform certain actions on the precommitted navigation, in particular redirecting. This updates the eventual destination, and potentially the state/info, of the `"push"` or `"replace"` navigation.
An example usage is as follows:

```js
navigation.addEventListener("navigate", e => {
e.intercept({
async precommitHandler(controller) {
if (await isLoginGuarded(e.destination)) {
controller.redirect("/login");
controller.redirect("/login", {state: "login-redirect", info: "some-info"});
}
}

Expand Down