files/en-us/web/api/navigation/traverseto/index.md
{{APIRef("Navigation API")}}
The traverseTo() method of the {{domxref("Navigation")}} interface navigates to the {{domxref("NavigationHistoryEntry")}} identified by the given {{domxref("NavigationHistoryEntry.key", "key")}}.
traverseTo(key)
traverseTo(key, options)
key
key of the {{domxref("NavigationHistoryEntry")}} to navigate to.options {{optional_inline}}
info {{optional_inline}}
info.An object with the following properties:
committed
finished
intercept() handler are fulfilled. This is equivalent to the {{domxref("NavigationTransition.finished")}} promise fulfilling, when the {{domxref("Navigation/navigatesuccess_event", "navigatesuccess")}} event fires.Either one of these promises rejects if the navigation has failed for some reason.
InvalidStateError {{domxref("DOMException")}}
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 navigations
navigation.addEventListener("navigate", (event) => {
event.intercept({
async handler() {
// Navigate to a different view,
// but the "home" button will always work.
},
});
});
{{Specifications}}
{{Compat}}