liveBook · Manning

Navigation

As explained in Vanilla Web

Movement among locations or views in a web application.

Navigation moves between locations or views in a web application. Start with the browser’s built-in behavior: links, forms, address-bar URLs, reloads, and Back and Forward all initiate navigation without a router. Unless JavaScript intercepts it, navigation loads a new document, replacing the current JavaScript context, application state, and focus; scroll position may also change. section 10.1.2

Most route changes should start from real links. Use programmatic navigation when an action finishes—for example, after saving a form or completing login. With a router listening for the Navigation API’s navigate event, navigation.navigate() can enter the same intercepted rendering flow as a link click or Back and Forward traversal, including focus and scroll handling. section 11.2

Keep the navigation contract small:

  • Choose whether to push a new history entry or replace the current one. Await navigation.navigate(...).finished when the caller needs the intercepted route handler to finish rendering; committed only confirms that the URL and entry changed. section 11.2
  • For a History API fallback, call pushState() or replaceState(), then render from the new location. pushState() does not fire popstate; that event handles later Back and Forward traversal. section 11.2
  • After same-document navigation, update document.title and active navigation links. For public, indexable routes, keep the canonical URL consistent; serve discoverable metadata from the server or static output rather than relying on client-side changes. section 11.1.3

Navigate after a save

After await saveSettings(formData), call await goTo("/settings/saved", { replace: true }). Replacing the entry avoids adding the pre-redirect location as another step in the user’s history; the helper delegates rendering to the normal navigation flow. section 11.2

Table 11.1 Deciding on storing state data in URL or in history entry

State

Belongs in the URL

Belongs in history entry state

Selected product

Yes, as /products/42.

No, because the route should be shareable.

Search filters

Usually, as query parameters.

Only if the filters are private or temporary.

Scroll position inside a panel

No.

Yes, because it belongs to the current browsing session.

Open disclosure panel

Maybe, if it should be shareable.

Yes, if it is only UI convenience.

Choose the URL for shareable route state, such as a selected product or search filters. Use history-entry state for session-specific UI details, such as a panel’s scroll position. section 11.2

How Vanilla Web covers it

How deep it goes
Works through completion promises, history behavior, metadata updates, and a fallback; shows route matching only as a call.
Examples
Uses a post-save route change, a route-metadata helper, and a table comparing URL state with history-entry state.
What it assumes
Assumes familiarity with links, forms, URLs, and JavaScript while starting from the browser’s native navigation behavior.
What you can do after
Build it from scratch with a navigation helper that delegates to the Navigation API or renders after a History API fallback.
How it connects
Connects navigation to client-side routing, the History API, document metadata, focus management, and scroll restoration.

Also explained in

Compare how 6 books explain navigation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.