Linking and navigating
Move between routes while preserving browser history, focus, scroll position, and useful loading feedback.
Use links for application URLs
The Core Link component performs client navigation for internal destinations and keeps normal anchor behavior available to the browser. Use links for destinations and buttons for actions.
Create src/components/ProjectNavigation.tsx
tsximport { Link } from "@tavojs/core/router";
import { Inline } from "@tavojs/ui";
export function ProjectNavigation() {
return (
<Inline as="nav" gap="md" aria-label="Projects">
<Link to="/projects">All projects</Link>
<Link to="/projects/active" scroll={false}>
Active projects
</Link>
</Inline>
);
}
Prefetch when intent is clear
prefetchRoute can resolve a likely destination before the click without changing the URL or rendering the route's pending component. Use it for focused or hovered high-probability links, not every route in the application. getRouteStatus exposes idle, loading, prefetching, ready, redirecting, and error states without duplicating the router state machine.
Create src/navigation/prefetch-projects.ts
tsimport { getRouteStatus, prefetchRoute } from "@tavojs/core/router";
export async function prefetchProjects() {
await prefetchRoute("/projects");
return getRouteStatus("/projects");
}