Skip to main content
TanStack Router provides comprehensive type safety across your entire routing layer, from route definitions to navigation and data access.

Route Type Registration

Register your route tree for global type inference:
Now all hooks and components have type information.

File-Based Routes

Generate type-safe routes from your file structure:
This creates:
  • Type definitions for all routes
  • Global route type registration
  • Autocomplete for paths and params

Route File

Type-Safe Parameters

Path Parameters

Path params are automatically inferred:

Parsed Parameters

Transform params with type safety:

Search Parameters

Define search param types with validators:

Type-Safe Navigation

Links are fully type-checked:
Invalid paths cause compile errors:
Programmatic navigation is type-safe:

From Parameter

Specify source route for relative navigation:

Type-Safe Data Access

Loader Data

Loader return types are inferred:

Context

Route context is fully typed:

Strict Mode

Strict Params

Enable strict parameter typing:
Strictly type search parameters:
With strict mode, only params defined in validateSearch are allowed.

Type Inference

Route by ID

Access route types by ID:

Route by Path

Access route types by path:

All Params

Get union of all route params:

Router Context Type

Define context type for dependency injection:
All routes inherit this context with full typing.

Type Helpers

ParsePathParams

Extract param types from path pattern:

ResolveFullSearchSchema

Resolve complete search schema including parent routes:

MakeRouteMatch

Create a route match type:

Generic Components

Build reusable type-safe components:

TSConfig Setup

Enable strict mode for best type safety:

Type Errors

Common Issues

Missing Router Registration

Wrong From Parameter

Invalid Navigation

Type Generation

Manual Generation

Watch Mode

In Package Scripts

Best Practices

Register your router type globally for complete type inference across your app.
Define search parameters with Zod, Valibot, or ArkType for runtime validation and type safety.
Use strict: true and strictNullChecks: true in tsconfig.json for maximum type safety.
Always specify from in hooks for route-specific types instead of loose union types.
Transform path params from strings to typed values using params.parse for better DX.

Next Steps

Search Params

Type-safe search parameter validation

Path Params

Type-safe path parameter parsing

Loaders

Type-safe data loading

Routes

Configure route type inference