Skip to main content
TanStack Router is a modern routing library for React that brings type-safety, built-in caching, and powerful URL state management to your applications.

Why TanStack Router?

TanStack Router goes beyond traditional routing solutions by providing:
  • 100% Type-Safe: Full TypeScript support with automatic type inference for routes, params, and search parameters
  • Built-in Caching: Intelligent data loading with automatic cache management
  • URL State Management: First-class support for search params as application state
  • Code-Based or File-Based Routing: Choose the routing style that fits your workflow
  • Nested Layouts: Powerful layout composition with route hierarchies
  • Data Loaders: Load data before rendering with built-in async support
  • Error Handling: Granular error boundaries at the route level
  • Path & Search Params: Type-safe params with validation support

Key Features

Type-Safe Navigation

Navigate with confidence using auto-complete and compile-time checks for all routes, params, and search parameters.

Smart Data Loading

Load data before rendering with loaders, built-in caching, and automatic invalidation strategies.

Search Params as State

Use URL search parameters as a single source of truth for application state with validation.

Nested Routes & Layouts

Build complex UI hierarchies with nested routes that share layouts and data.

How It Works

TanStack Router is built around a few core concepts:
  1. Routes - Define your application structure using route definitions
  2. Router - Create a router instance that manages navigation and state
  3. RouterProvider - Provide the router to your React tree
  4. Navigation - Use Link components and hooks for type-safe navigation
  5. Data Loading - Define loaders to fetch data before rendering
TanStack Router works seamlessly with popular data fetching libraries like TanStack Query, SWR, and Apollo Client.

Two Routing Approaches

TanStack Router supports both routing paradigms:

Code-Based Routing

Define routes programmatically with full control and type inference:
import { createRoute, createRouter } from '@tanstack/react-router'

const rootRoute = createRootRoute({
  component: RootLayout,
})

const indexRoute = createRoute({
  getParentRoute: () => rootRoute,
  path: '/',
  component: Home,
})

const router = createRouter({
  routeTree: rootRoute.addChildren([indexRoute]),
})

File-Based Routing

Organize routes by file structure with automatic route generation:
// src/routes/__root.tsx
export const Route = createRootRoute({
  component: RootLayout,
})

// src/routes/index.tsx
export const Route = createFileRoute('/')({  
  component: Home,
})

Next Steps

Ready to get started? Choose your path:

Installation

Install TanStack Router and set up your project

Quickstart Guide

Build your first router in under 5 minutes

Core Concepts

Dive deep into routing fundamentals

API Reference

Explore the complete API documentation

Community & Support

Join the TanStack community:
TanStack Router is part of the TanStack family of libraries, including TanStack Query, TanStack Table, and more!

Build docs developers (and LLMs) love