Routing and navigation
Navigate between typed file routes while preserving browser history, focus, scroll, and pending state.
Link and scroll behavior
The Core Link performs SPA navigation and sets aria-current on the active destination. New routes begin at the top, hashes scroll into view, and browser back or forward restores saved positions.
tsximport { Link } from "@tavojs/core/router";
import { Inline } from "@tavojs/ui";
export function AccountNavigation() {
return <Inline as="nav" aria-label="Account">
<Link to="/account/profile">Profile</Link>
<Link to="/account/security" scroll={false}>Security</Link>
</Inline>;
}Prefetch intentionally
Prefetch routes when intent is clear, such as pointer hover or focus on a high-probability destination. Prefetching resolves work without changing the URL or rendering the target page's pending component. Route status APIs let interface code show loading, prefetching, ready, or error states without duplicating the router state machine.
tsimport { getRouteStatus, prefetchRoute } from "@tavojs/core/router";
export async function prepareReports() {
await prefetchRoute("/reports");
return getRouteStatus("/reports");
}Subscribe and inspect responsibly
Auto Pages exposes synchronous route state and disposable subscriptions from @tavojs/core/router. Development inspection lives under @tavojs/core/dev, while tavo routes and tavo inspect route show the generated graph without adding application code.
Use
getResolvedRouteandgetRouteStatusfor current resolution state.Use
subscribeAvailableRoutesandsubscribeRouteStatuswhen interface state must react to route changes.Run
tavoroutes,tavoinspect route <path>--json, or importgetAutoPagesInspectionfrom@tavojs/core/devduring development.
tsimport {
getAvailableRoutes,
getCurrentPathname,
subscribePathname
} from "@tavojs/core/router";
console.log(getCurrentPathname(), getAvailableRoutes());
const unsubscribe = subscribePathname((pathname) => {
console.log("Route changed:", pathname);
});
// Call when this observer's owner is disposed.
unsubscribe();Link behavior and accessibility
Linkrenders a real anchor and addsaria-current="page" when its resolved route is active.Only an unmodified primary click to the same origin is intercepted. External URLs, downloads, modified clicks, new-window targets, and same-page hashes keep browser behavior.
replace defaults to false. Navigation scrolls to the top or hash by default; scroll: false preserves the current position. Back and forward restore saved positions.
When an i18n service is registered, internal destinations are localized and active matching ignores the locale prefix.
tstype LinkProps = {
to: string;
replace?: boolean;
scroll?: boolean;
className?: string;
children?: Child;
};Standalone router reference
The standalone router is intended for embedded or client-only route areas. Do not create a second top-level router inside a file-routed application.
RouterProvidercan render explicit children or the matched route component.After navigation it announces status, focuses
data-tavo-route-focus, main, h1, or role=main, and restores scroll.navigateis a no-op during server rendering.Routerparams are decoded strings.
tsxconst router = createRouter([
{ path: "/", component: Home },
{ path: "/teams/:id", component: Team }
]);
router.navigate("/teams/core", { replace: false, scroll: true });
router.getPathname();
router.match("/teams/core"); // { route, params: { id: "core" } }
<RouterProvider
router={router}
notFound={<NotFound />}
busy={false}
contentId="route-content"
/>Look up exact public types
Follow linked API names to their canonical TypeScript declarations and package boundaries.