Vidact Start
Navigation
Move between routes without a page reload using Link and the client's navigate function.
Vidact Start renders every route on the server, but once the page has hydrated, moving between routes happens in the browser. The server sends only the new loader data, and the client swaps the route content in place.
Link
Link renders an <a> element. On the server it is a normal anchor, so the page works before JavaScript loads. After hydration, a click on it is intercepted and handled as a client navigation.
import { Link } from '@vidact/start'export function Nav() { return ( <nav> <Link href="/">Home</Link> <Link href="/blog">Blog</Link> <Link href="/login" replace>Sign in</Link> </nav> )}Link accepts every attribute an <a> accepts, plus two of its own:
| Prop | Effect |
|---|---|
replace | Replace the current history entry instead of pushing a new one |
reloadDocument | Opt out of client navigation and let the browser load the page |
Clicks that should not be intercepted are left alone automatically: modified clicks (Ctrl, Cmd, Shift, Alt), non-primary buttons, links with a target other than _self, a download attribute, rel="external", or a different origin, and clicks whose default was already prevented.
Marking the active link
Route components receive requestUrl. Compare its pathname to the link target:
export function Nav({ requestUrl }: { requestUrl: string }) { const pathname = new URL(requestUrl).pathname return ( <Link aria-current={pathname === '/blog' ? 'page' : undefined} href="/blog"> Blog </Link> )}Scroll and focus
By default the page scrolls to the top after a navigation. Pass scroll: false to navigate when you are updating a filter or a tab and want the viewport to stay put. Focus is not moved automatically; move it yourself in an effect if the new content needs it for accessibility.