NavigationPrecommitController: redirect() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The redirect() method of the NavigationPrecommitController interface redirects the browser to a specified URL and specifies history behavior and any desired state information.

Syntax

js
redirect(url, options)

Parameters

url

The URL to redirect to.

options Optional

An options object, the properties of which can include:

state Optional

Contains any state information you want to pass along with the navigation; for example, for logging or tracking purposes. This can be represented by any value type. The state for the navigation can subsequently be retrieved via the NavigationHistoryEntry.getState() method of the resulting history entry.

history Optional

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:

  • If the original navigation occurred as a result of a Navigation.navigate() call, the value will be whatever was specified in the navigate() call's history option.
  • Otherwise, the value used is usually push, but it will become replace if the redirect points to the same URL as the pre-navigation URL.
push

Adds a new NavigationHistoryEntry to the navigation history, and clears any available forward navigation (that is, if the user previously navigated to other locations, then used the back button to return back through the history before initiating the navigation that caused the redirect).

replace

Replaces the Navigation.currentEntry with the resulting new NavigationHistoryEntry.

Note: The redirect() method 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.

Return value

None (undefined).

Exceptions

InvalidStateError DOMException

Thrown if:

SyntaxError DOMException

Thrown if the specified url is invalid.

SecurityError DOMException

Thrown if the current document is unable to have its URL rewritten to the provided redirect url.

Examples

See the main NavigationPrecommitController page for an example.

Specifications

Specification
HTML
# dom-navigationprecommitcontroller-redirect

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
redirect
Chrome – Full support
Chrome 141 (Release date: 2025-09-30)
footnote Full support
Edge – Full support
Edge 141 (Release date: 2025-10-03)
footnote Full support
Firefox – Full support
Firefox 147 (Release date: 2026-01-13)
footnote Full support
Opera – Full support
Opera 125 (Release date: 2025-12-04)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 141 (Release date: 2025-09-30)
footnote Full support
Firefox for Android – Full support
Firefox for Android 147 (Release date: 2026-01-13)
footnote Full support
Opera Android – Full support
Opera Android 93 (Release date: 2025-11-25)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 141 (Release date: 2025-09-30)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also