History entry state is small, serializable data attached to one browser session-history entry. Use it for transient view details—such as an active tab or panel scroll position—that should return with Back and Forward navigation. Keep important, shareable route state in the URL. section 11.2
With the Navigation API, pass state to navigation.navigate(), read it with navigation.currentEntry.getState(), and update it without navigating with navigation.updateCurrentEntry(). The older History API accepts state in pushState() or replaceState(); read it through history.state or popstate event.state. It has no current-entry update method, so updating state requires replaceState() with the current URL. section 11.2
Choose storage according to whether the state belongs in a shareable route or only in the current browsing session:
- Put a selected product in the URL; it should be shareable. section 11.2
- Put search filters in the URL unless they are private or temporary. section 11.2
- Use entry state for a panel’s scroll position or a convenience-only disclosure panel. 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. |
Compare which kinds of state belong in the URL and which belong in an individual history entry. section 11.2
