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
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