Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. Navigation
  4. traverseTo()

Navigation: traverseTo() method

Limited availability

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

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

ThetraverseTo() method of theNavigation interface navigates to theNavigationHistoryEntry identified by the givenkey.

Syntax

js
traverseTo(key)traverseTo(key, options)

Parameters

key

Thekey of theNavigationHistoryEntry to navigate to.

optionsOptional

An options object containing the following properties:

infoOptional

Developer-defined information to be passed along to thenavigate event, made available inNavigateEvent.info. This can be any data type. You might, for example, wish to display newly-navigated content with a different animation depending on how it was navigated to (swipe left, swipe right, or go home). A string indicating which animation to use could be passed in asinfo.

Return value

An object with the following properties:

committed

APromise which will fulfill when the visible URL has changed and a newNavigationHistoryEntry has been created.

finished

APromise which will fulfill when all promises returned by theintercept() handler are fulfilled. This is equivalent to theNavigationTransition.finished promise fulfilling, when thenavigatesuccess event fires.

Either one of these promises rejects if the navigation has failed for some reason.

Exceptions

InvalidStateErrorDOMException

Thrown if theNavigation.currentEntry'sNavigationHistoryEntry.index value is -1, meaning the currentDocument is not yet active, or if the navigation history list does not contain aNavigationHistoryEntry with the specified key, or if the currentDocument is unloading.

Examples

Set up home button

js
function initHomeBtn() {  // Get the key of the first loaded entry  // so the user can always go back to this view.  const { key } = navigation.currentEntry;  backToHomeButton.onclick = () => {    navigation.traverseTo(key);  };}// Intercept navigate events, such as link clicks, and// replace them with single-page navigationsnavigation.addEventListener("navigate", (event) => {  event.intercept({    async handler() {      // Navigate to a different view,      // but the "home" button will always work.    },  });});

Specifications

Specification
HTML
# dom-navigation-traverseto-dev

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp