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 |
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





