Introduction to TanStack Router
TanStack Router is a modern, type-safe routing solution with built-in caching and URL state management for React, Solid, and Vue applications. It provides a powerful and flexible API for building complex routing structures while maintaining excellent TypeScript support.What is TanStack Router?
TanStack Router is a fully type-safe router that goes beyond traditional routing libraries by integrating data loading, caching, and URL state management directly into the routing layer. It’s designed to help you build scalable applications with confidence, leveraging TypeScript’s type system to catch errors at compile time.TanStack Router is part of the TanStack family of tools, which includes TanStack Query, TanStack Table, and more. It’s designed with the same principles of developer experience and type safety.
Key Features
TanStack Router provides a comprehensive set of features that make building modern web applications easier:Type-Safe Navigation
Every route, parameter, and search param is fully typed. The router provides autocomplete and type checking for all navigation, ensuring you never navigate to a non-existent route or use incorrect parameters.Built-in Data Loading
Load data directly in your route definitions using loaders. The router handles loading states, errors, and caching automatically.URL State Management
Manage complex application state in the URL with type-safe search params. TanStack Router provides built-in validation and serialization.Code-Based & File-Based Routing
Choose between code-based routing for full control or file-based routing for automatic route generation:Automatic Code Splitting
Lazy load routes and their dependencies automatically with built-in code splitting support:Nested Routing
Build complex layouts with nested routes and outlets:Search Param Validation
Validate and parse search parameters with support for Zod, Valibot, and ArkType:Built-in DevTools
Debug your routing with the included DevTools component:Preloading & Caching
Automatically preload routes on hover or intent, with configurable caching strategies:Server-Side Rendering (SSR)
Full SSR support with streaming, hydration, and server-side navigation.When to Use TanStack Router
TanStack Router is ideal for:Complex Data Requirements
When your routes need to load data with sophisticated caching and error handling.
URL State Management
When you need to manage application state in the URL with validation and type safety.
Large-Scale Applications
When building applications that need automatic code splitting and performance optimization.
Framework Support
TanStack Router supports multiple frameworks:React
Full support for React 18+ with hooks and components
Solid
Native Solid.js integration with fine-grained reactivity
Vue
Vue 3 support with composition API
How It Compares
TanStack Router stands out from other routing solutions:| Feature | TanStack Router | React Router | Next.js App Router |
|---|---|---|---|
| Type-Safe Routes | ✅ Full | ⚠️ Partial | ⚠️ Partial |
| Type-Safe Params | ✅ | ❌ | ❌ |
| Built-in Data Loading | ✅ | ⚠️ Limited | ✅ |
| Search Param Validation | ✅ | ❌ | ❌ |
| Built-in Caching | ✅ | ❌ | ✅ |
| Framework Agnostic | ✅ | ❌ React only | ❌ React only |
| File-Based Routing | ✅ Optional | ❌ | ✅ Required |
| Code-Based Routing | ✅ | ✅ | ⚠️ Limited |
Architecture Overview
TanStack Router consists of several key packages:@tanstack/router-core- Framework-agnostic core routing logic@tanstack/react-router- React-specific bindings and components@tanstack/solid-router- Solid-specific bindings and components@tanstack/vue-router- Vue-specific bindings and components@tanstack/router-plugin- Vite/Webpack/Rspack plugin for file-based routing@tanstack/router-devtools- Development tools for debugging
Next Steps
Ready to get started? Follow our guides:Installation
Install TanStack Router in your project
Quick Start
Build your first application with TanStack Router