Build full-stack web apps with a single type-safe router
B

Build full-stack web apps with a single type-safe router

Build full-stack web apps with a single type-safe router

UI
14,727 stars
N/A forks
N/A contributors

README

Project documentation from GitHub

One Router to Rule Them All: Full-Stack Type Safety with TanStack Router

If you've ever built a full-stack TypeScript application, you know the feeling. You get beautiful, end-to-end type safety for your data layer with tools like tRPC, but your routing layer often feels like a separate, loosely-coupled part of the puzzle. You define routes on the server, then manually mirror them on the client, hoping your links and navigations don't break with a typo. What if your router could bridge that gap?

TanStack Router is a new type-safe router for React that aims to do exactly that. It's not just about managing client-side state; it's designed to be the single source of truth for routing across your entire application stack, from the frontend all the way to your backend server.

What It Does

TanStack Router is a framework-agnostic routing library (with first-class React support) built with a relentless focus on type safety and developer experience. At its core, it uses your route definitions—configured as a plain object or via a file-based system—to generate a fully-typed router.

The magic happens when you use these types. Every Link, useNavigate call, or parameter access is strictly validated against your defined routes. This means you catch broken links at compile time, not in production. But it goes further: by structuring your router to be shared between client and server, you can ensure your backend route handlers and your frontend route consumers are always in sync.

Why It's Cool

The type safety is the headline feature, but the implementation is what makes it stand out. It uses TypeScript's type system incredibly aggressively to infer everything it can from your route configuration. You define a route with a parameter like user/:userId, and instantly, useParams() knows it returns an object with a userId string. No manual type definitions needed.

Beyond the types, it packs features modern apps expect:

  • Built-in Loaders: Fetch data for a route before it renders, with built-in caching and invalidation via TanStack Query integration.
  • File-Based Routing: Optional filesystem-based configuration that feels intuitive and keeps your code organized.
  • Search Param Management: Full type safety for URL search parameters, treating them as first-class state.
  • Relative Navigation: Navigate to sibling or child routes without hardcoding full paths.

The vision is to use this single, type-safe router configuration to generate not just your client-side routes, but also the routing logic for your backend framework (like Express, Fastify, or your Next.js API routes). This eliminates the duplication and drift that inevitably happens when routes are defined

Did you like this issue?

Join our weekly newsletter

Related Projects

Love discovering amazing projects?

Help us continue bringing you the best open-source discoveries every week.

Back to Projects
Last updated: Dec 20, 2025