Capítulo 47 de 57
TanStack Router fully infers and pipes types through the entire routing experience; achieving this for shared hooks/components requires a from context hint (or strict: false) since component context can't otherwise track changing route types.
Register interface (declare module '@tanstack/react-router' { interface Register { router: typeof router } }) is what makes top-level exports like Link, useNavigate, useParams type-safe project-wide.getParentRoute: In code-based routing, child routes must reference their parent via getParentRoute so parent context/search/params types propagate down; omitting this loses type information.from hint: Hooks/components that need context from the whole router (e.g. useNavigate, Route.useParams) accept a from option (route ID or path) telling TypeScript where in the hierarchy the component renders.from runtime error: Passing a from that satisfies TypeScript but doesn't match the actual rendering route throws a runtime error, it's checked, not just decorative.strict: false: For shared components that don't know their route, this option relaxes the hook (e.g. useSearch({ strict: false })) to accept a union of all possible types instead of erroring.createRootRouteWithContext: Factory for typing router context, requiring you to fulfill the same context contract when creating the router.from/to narrows unions (search/params) TypeScript has to check; using broad types like LinkProps directly is expensive, prefer as const satisfies LinkProps<...>.export const Route = createFileRoute('/posts')({
component: PostsComponent,
})
function PostsComponent() {
const params = Route.useParams()
const search = Route.useSearch()
const navigate = useNavigate({ from: Route.fullPath })
}
Route.useParams) versus router-wide hooks that need an explicit from hint.function MyComponent() {
const search = useSearch({ strict: false })
}
from.from (or Route.fullPath) to router-wide hooks used inside a specific route to get precise, narrowed types and catch runtime mismatches.strict: false rather than guessing a from.from/to, prefer as const satisfies LinkProps<...> over the bare LinkProps type, and consider object-syntax addChildren for large code-based route trees.createRootRouteWithContext and context typing are detailed there.ValidateLinkOptions and friends for building type-safe wrapper components without the LinkProps performance trap.