Skip to main content
This quickstart guide will help you create a fully functional router-based React application in under 5 minutes.

Prerequisites

Before starting, make sure you have:
  • Node.js 20.19 or higher installed
  • A React application set up (or create one with Vite)
  • TanStack Router installed (see Installation)

Step 1: Create Your First Routes

Let’s build a simple application with a home page and an about page using code-based routing.

Complete Example

Here’s the full code for reference:

Step 2: Add Data Loading

TanStack Router can load data before rendering routes. Let’s add a loader to fetch posts:
Loaders run before the route component renders, ensuring data is ready when your component mounts.

Step 3: Add Path Parameters

Create dynamic routes with type-safe path parameters:

Step 4: Add DevTools (Optional)

Install and add the DevTools for debugging:
main.tsx
DevTools are automatically tree-shaken in production builds, so you can safely include them in your root route.

Type-Safe Navigation

TanStack Router provides full type-safety for navigation:

Next Steps

Congratulations! You’ve built your first TanStack Router application. Here’s what to explore next:

Core Concepts

Learn the fundamentals of routing, navigation, and data loading

File-Based Routing

Organize routes by file structure with automatic generation

Search Parameters

Master type-safe URL search parameters as application state

Error Handling

Implement robust error boundaries and fallbacks

Common Patterns

Route-Level Code Splitting

Lazy load route components for better performance:

Search Parameter Validation

Add type-safe search params with validation:

Nested Layouts

Create layouts that wrap multiple child routes:
Make sure to include <Outlet /> in parent routes to render child route content.