react-router

Implements type-safe React routing with TanStack Router hooks, components, and file-based route setup.

Updated May 26, 2026
One-click install
npx skills add https://github.com/Albo-Club/albo-os --skill react-router-albo-club
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-router
Source: https://github.com/Albo-Club/albo-os/tree/main/.agents/skills/tanstack-react-router
Command: npx skills add https://github.com/Albo-Club/albo-os --skill react-router-albo-club

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 app involves many moving parts—Vite plugin configuration, route registration, type-safe hooks, and SSR-aware patterns—and small mistakes (like calling hooks in loaders or misplacing providers) cause subtle bugs. This Skill provides the correct patterns and API reference for the React bindings of TanStack Router. ## Core Features & Use Cases - Complete Setup Guide: Covers installing @tanstack/react-router, configuring the Vite plugin with auto code-splitting, creating root and file-based routes, and registering router types for full type inference. - Hooks and Components Reference: Documents useRouter, useNavigate, useSearch, useParams, useLoaderData, useMatches, useBlocker, Link, Outlet, Navigate, Await, and CatchBoundary with working examples. - React-Specific Patterns: Explains createLink with forwardRef, reusable components across routes, auth provider ordering with RouterProvider, and common mistakes like using React hooks inside beforeLoad or loader functions. - Use Case: You are building a React SPA with TanStack Router and need to add a protected route that reads auth state, navigates after form submission, and renders deferred loader data with Suspense—this Skill gives you the exact correct code for each step. ## Quick Start Ask the AI to set up TanStack Router file-based routing in your React Vite project with a root layout, navigation links, and type-safe route registration.

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 plus the @tanstack/router-plugin dev dependency, add tanstackRouter({ target: 'react' }) to your Vite plugins before react(), create a root route with createRootRoute, add file-based routes with createFileRoute, and render RouterProvider with the generated routeTree.

How do I navigate programmatically with TanStack Router?

Use the useNavigate hook from @tanstack/react-router and call navigate({ to: '/posts/$postId', params: { postId: '123' } }). For user-clickable elements, prefer the type-safe Link component instead.

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, runs loaders on the client by default, and uses its own hooks like useSearch and useLoaderData.

Why can't I use React hooks in TanStack Router loaders?

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

How do I read search params in TanStack Router?

Use the useSearch hook with the route path, for example useSearch({ from: '/products' }), to access validated search params with full type safety. Validate them in the route's validateSearch option.

Why does Await throw an error in my TanStack Router app?

The Await component for deferred loader data requires a Suspense ancestor. Wrap it in <Suspense fallback={...}> so the deferred promise has fallback UI while resolving.