navigationMemory()
Restore a list and its scroll position.
Try the example
Scroll the project list and save your position. Scroll somewhere else, then restore. The saved position is held in memory for this page only.
Scroll the list to begin.
Add it to your project
- Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
- Connect the behavior. Copy the JavaScript tab and call its exported
mount(element)after your component’s elements exist. Replace simulated delays and data operations with your own application code. - Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.
API and lifecycle
Create a memory instance and save(key, list, state) before leaving a list. It stores scroll coordinates plus a cloned state object; read(key) returns that state. Use keys that identify the route and list.
- Interface
max; save/read/restore/clear- Lifecycle
- Restore filters and render the list before calling restore(key, list). It returns whether a saved entry exists. clear() removes all entries; storage is memory-only, with 30 entries by default.
Accessibility and safety
Implementation notes
Initialize after the DOM is available. Keep native controls and keyboard interactions intact; release listeners and timers on unmount.
Restore a useful position without stealing focus. Avoid sharing an instance across user sessions or storing sensitive filter values unnecessarily.
What to check
Scroll and filter a list, visit a detail view and return. Confirm state is restored after rendering and that missing entries are handled normally.