> ## Documentation Index
> Fetch the complete documentation index at: https://inttegro-cogni.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# TanStack Router

> Put TanStack route preloading behind Cogni's admission and quality accounting.

`@inttegro/cogni-tanstack-router` wraps TanStack Router's awaitable `preloadRoute()` contract in a
familiar link. Route parameters, search state, active state, and ordinary anchor props stay with the
router; Cogni owns whether predictive work starts.

> [!NOTE]
>
> This guide follows the `0.1` API and TanStack Router 1.x. Confirm the latest published version and
> migration notes before installing a newer `0.x` release.

## Replace Link

```tsx theme={null}
import { CogniProvider } from "@inttegro/cogni-react";
import { PredictiveLink } from "@inttegro/cogni-tanstack-router";

export function Navigation() {
  return (
    <CogniProvider opaqueUserKey={session.opaqueUserKey}>
      <PredictiveLink to="/orders">Orders</PredictiveLink>
    </CogniProvider>
  );
}
```

The adapter disables the link's independent `preload` behavior, then calls
`router.preloadRoute()` after Cogni admits the candidate. The returned promise keeps the prediction
in its loading state until TanStack's speculative match lane settles.

When TanStack begins a matching navigation, the adapter attributes reuse. If the user leaves,
prevents the event, opens another context, or navigates elsewhere, the prediction is not credited.

## Keep router cache policy

Cogni does not replace `preloadStaleTime`, `preloadGcTime`, route loaders, or an external query
cache. Those settings decide whether the route can reuse settled work. Cogni decides whether the
speculation was worth starting and measures whether committed navigation used it.

Avoid enabling a second default preload strategy for these links. `PredictiveLink` passes
`preload={false}` internally so hover does not bypass Cogni's budget.

Use `predictionKey`, `policy`, `cost`, `priority`, and `estimatedBytes` when the default route
identity needs more context. Cogni starts with its conservative probability and 30 second reuse
horizon, then learns from actual reuse and waste. Override either value when the application has
stronger evidence.

See [React](https://inttegro-cogni.mintlify.site/cogni/react.md) for provider ownership and [Scheduling and intent](https://inttegro-cogni.mintlify.site/cogni/scheduling-and-intent.md) for
the admission sequence.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.