react-router

Implements React bindings for TanStack Router including hooks, components, and type-safe navigation.

Updated Dec 21, 2025
One-click install
npx skills add https://github.com/Angael/veles --skill react-router-angael
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-router
Source: https://github.com/Angael/veles/tree/main/.agents/skills/react-router
Command: npx skills add https://github.com/Angael/veles --skill react-router-angael

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-router, @tanstack/router-plugin, @tanstack/react-router-devtools.

What problem does it solve? Setting up TanStack Router in a React application involves many moving parts—Vite plugin configuration, route registration, type-safe hooks, and SSR hydration—and common mistakes like calling React hooks inside loaders or misplacing auth providers cause subtle bugs. ## Core Features & Use Cases - Complete Setup Guide: Walks through file-based routing with Vite, including the router plugin, root route creation, and the required Register interface for type safety. - Hooks and Components Reference: Documents useNavigate, useSearch, useParams, useLoaderData, useMatches, Link, Outlet, Navigate, Await, and CatchBoundary with working examples. - Mistake Prevention: Covers high-impact errors such as using React hooks in beforeLoad/loader, recreating the router on auth changes, and missing Suspense boundaries for deferred data. - Use Case: When building a React SPA with TanStack Router, use this Skill to correctly wire an auth provider around RouterProvider and implement type-safe navigation with createLink and forwardRef. ## Quick Start Set up TanStack Router in my React Vite app with file-based routing, a root layout with navigation links, and full type safety.

Frequently Asked Questions about react-router

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up TanStack Router with React and Vite?

Install @tanstack/react-router and the @tanstack/router-plugin dev dependency, then add tanstackRouter({ target: 'react' }) to your Vite plugins before react(). Create a root route with createRootRoute, define route files with createFileRoute, and render RouterProvider with the generated routeTree.

How do I get type-safe navigation with TanStack Router Link?

Register your router instance via the Register interface using declare module '@tanstack/react-router'. After registration, Link, useNavigate, useSearch, and useParams gain full type inference for paths, params, and search schemas without any manual annotations.

Is @tanstack/react-router the same as react-router-dom?

No, they are completely different libraries with different APIs. TanStack Router is client-first with fully inferred types and loaders that run on the client by default, while react-router-dom uses a different route definition and data-loading model.

Why can't I use React hooks inside a TanStack Router loader?

Loaders and beforeLoad are plain async functions, not React components, so hooks like useAuth cannot be called in them. Pass auth state through router context instead and read it via the context argument in beforeLoad.

How do I use auth context with TanStack Router RouterProvider?

Create the router once with a placeholder context value, then inject live auth state through RouterProvider's context prop inside an inner component that reads your auth hook. Never recreate the router on auth changes, as that resets caches and rebuilds the route tree.

Why does the Await component throw an error in TanStack Router?

The Await component for deferred loader data requires a React Suspense ancestor to provide a fallback UI. Wrap Await in a Suspense boundary with a fallback element so the deferred promise has somewhere to suspend while loading.