Skip to content

You get scroll restoration automatically with Navi: the router remembers scroll positions as the user moves through the app and restores them on return visits.

Positions are keyed by path plus normalized query. /users?sort=asc and /users?sort=desc remember separate positions, so two sorted views of the same list do not fight over one offset. The cache is capacity-bounded with O(1) eviction, so long sessions do not grow memory without bound.

Two levels of opt-out exist:

Level Mechanism
Whole navigation Pass reset_scroll: true on a Link to start the target position from the top.
Per navigation call NavigateOptions.reset_scroll does the same for programmatic navigation.
use navi_router::components::Link;
Link::new("/dashboard")
.reset_scroll(true)
.child("Dashboard (from the top)")
.build()

The ScrollRestoration component attaches a scroll-tracking node to your UI. Give it a handle id:

use navi_router::components::ScrollRestoration;
ScrollRestoration::node("main-scroll").build()

ScrollRestoration::set_capacity(capacity) bounds how many remembered positions are kept at once.