Overview
onNavigate(fn) subscribes to pathAtom from the router scope. Whenever the path changes (via navigateTo, back/forward, etc.), fn receives the new path string.
Use it for side effects — analytics, scroll-to-top, closing menus. Do not use it to read route params; use paramsAtom / useUtils() instead.
Navigation APIs
|
API
|
Role
|
Notes
|
|---|---|---|
onNavigate(fn)
| Side effects | Callback on path change; may return cleanup. |
pathAtom
| Reactive path | Read/write current pathname. |
paramsAtom
| Route params | Matched dynamic segments — not via onNavigate. |
onNavigate — react to route changes
onNavigate subscribes to pathAtom. Clicking a route calls navigateTo — the log is written from the onNavigate callback, not from the click handler.