This file provides guidance to AI assistants when working with the TanStack Router codebase.
TanStack Router is a type-safe router with built-in caching and URL state management for React and Solid applications. This monorepo contains two main products:
- TanStack Router - Core routing library with type-safe navigation, search params, and path params
- TanStack Start - Full-stack framework built on top of TanStack Router
Router Core:
router-core/- Framework-agnostic core router logicreact-router/- React bindings and componentssolid-router/- Solid bindings and componentshistory/- Browser history management
Tooling:
router-cli/- CLI tools for code generationrouter-generator/- Route generation utilitiesrouter-plugin/- Universal bundler plugins (Vite, Webpack, ESBuild, Rspack)router-vite-plugin/- Vite-specific plugin wrappervirtual-file-routes/- Virtual file routing system
Developer Experience:
router-devtools/- Router development toolsrouter-devtools-core/- Core devtools functionalityreact-router-devtools/- React-specific devtoolssolid-router-devtools/- Solid-specific devtoolseslint-plugin-router/- ESLint rules for router
Adapters:
zod-adapter/- Zod validation adaptervalibot-adapter/- Valibot validation adapterarktype-adapter/- ArkType validation adapter
Start Framework:
start/- Core start frameworkreact-start/- React Start frameworksolid-start/- Solid Start frameworkstart-*packages - Various start framework utilities
Documentation is organized in docs/:
docs/router/- Router-specific documentationdocs/start/- Start framework documentation- Each has
framework/react/andframework/solid/subdirectories
Extensive examples in examples/:
examples/react/- React router examplesexamples/solid/- Solid router examples- Examples range from basic usage to complex applications
e2e/- End-to-end tests organized by framework- Individual packages have
tests/directories - Uses Playwright for e2e testing
# Install dependencies
pnpm install
# Build all packages (affected only)
pnpm build
# Build all packages (force all)
pnpm build:all
# Development mode with watch
pnpm dev
# Run all tests
pnpm test
# Run tests in CI mode
pnpm test:ci# Run unit tests
pnpm test:unit
# Run e2e tests
pnpm test:e2e
# Run type checking
pnpm test:types
# Run linting
pnpm test:eslint
# Run formatting check
pnpm test:format
# Fix formatting
pnpm prettier:write# Target specific package
npx nx run @tanstack/react-router:test:unit
npx nx run @tanstack/router-core:test:types
npx nx run @tanstack/history:test:eslint
# Target multiple packages
npx nx run-many --target=test:eslint --projects=@tanstack/history,@tanstack/router-core
# Run affected tests only (compares to main branch)
npx nx affected --target=test:unit
# Exclude certain patterns
npx nx run-many --target=test:unit --exclude="examples/**,e2e/**"
# List all available projects
npx nx show projectsFor even more precise test targeting within packages:
# Navigate to package directory first
cd packages/react-router
# Run specific test files
npx vitest run tests/link.test.tsx
npx vitest run tests/ClientOnly.test.tsx tests/Scripts.test.tsx
# Run tests by name pattern
npx vitest run tests/ClientOnly.test.tsx -t "should render fallback"
npx vitest run -t "navigation" # Run all tests with "navigation" in name
# Exclude test patterns
npx vitest run --exclude="**/*link*" tests/
# List available tests
npx vitest list tests/link.test.tsx
npx vitest list # List all tests in package
# Through nx (passes args to vitest)
npx nx run @tanstack/react-router:test:unit -- tests/ClientOnly.test.tsx
npx nx run @tanstack/react-router:test:unit -- tests/link.test.tsx tests/Scripts.test.tsx# Navigate to an example
cd examples/react/basic
# Run the example
pnpm dev- Setup:
pnpm installandpnpm exec playwright install - Build:
pnpm build:allorpnpm devfor watch mode - Test: Make changes and run relevant tests (use nx for targeted testing)
- Examples: Navigate to examples and run
pnpm devto test changes
This repository uses Nx for efficient task execution:
- Caching: Nx caches task results - repeated commands are faster
- Affected: Only runs tasks for changed code (
nx affected) - Targeting: Run tasks for specific packages or combinations
- Parallel Execution: Multiple tasks run in parallel automatically
- Dependency Management: Nx handles build order and dependencies
This is a pnpm workspace with packages organized by functionality:
- Core packages provide the fundamental router logic
- Framework packages provide React/Solid bindings
- Tool packages provide development utilities
- Start packages provide full-stack framework capabilities
- Type Safety: Extensive use of TypeScript for type-safe routing
- Framework Agnostic: Core logic separated from framework bindings
- Plugin Architecture: Universal bundler plugins using unplugin
- File-based Routing: Support for both code-based and file-based routing
- Search Params: First-class support for type-safe search parameters
- Internal Links: Always write relative to
docs/folder (e.g.,./guide/data-loading) - Examples: Each major feature should have corresponding examples
- Type Safety: Document TypeScript patterns and type inference
- Framework Specific: Separate docs for React and Solid when needed
During prompt-driven development, always run unit and type tests to ensure validity. If either of these fail, do not stop or proceed (unless you have repeatedly failed and need human intervention).
You can run these (or the ones you are working on) after each big change:
pnpm test:eslint # Linting
pnpm test:types # TypeScript compilation
pnpm test:unit # Unit tests
pnpm test:build # Build verificationFor comprehensive testing:
pnpm test:ci # Full CI test suite
pnpm test:e2e # End-to-end testsFor targeted testing (recommended for efficiency):
# Test only affected packages
npx nx affected --target=test:unit
npx nx affected --target=test:types
npx nx affected --target=test:eslint
# Test specific packages you're working on
npx nx run @tanstack/react-router:test:unit
npx nx run @tanstack/router-core:test:types
# Test specific files/functionality you're working on
cd packages/react-router
npx vitest run tests/link.test.tsx -t "preloading"
npx vitest run tests/useNavigate.test.tsx tests/useParams.test.tsxPro Tips:
- Use
npx vitest listto explore available tests before running - Use
-t "pattern"to focus on specific functionality during development - Use
--excludepatterns to skip unrelated tests - Combine nx package targeting with vitest file targeting for maximum precision
The monorepo uses workspace dependencies extensively:
- Core packages are dependencies of framework packages
- Framework packages are dependencies of start packages
- All packages use workspace protocol (
workspace:*)
- Node.js: Required for development
- pnpm: Package manager (required for workspace features)
- Playwright: Required for e2e tests (
pnpm exec playwright install)
- Use file-based routing in
src/routes/directories - Or use code-based routing with route definitions
- Run route generation with CLI tools
- Build packages:
pnpm buildorpnpm dev - Run example apps to test functionality
- Use devtools for debugging router state
Available Test Targets per Package:
test:unit- Unit tests with Vitesttest:types- TypeScript compilation across multiple TS versionstest:eslint- Linting with ESLinttest:build- Build verification (publint + attw)test:perf- Performance benchmarksbuild- Package building
Granular Test Targeting Strategies:
- Package Level: Use nx to target specific packages
- File Level: Use vitest directly to target specific test files
- Test Level: Use vitest
-tflag to target specific test names - Pattern Level: Use vitest exclude patterns to skip certain tests
Example workflow:
# 1. Test specific package
npx nx run @tanstack/react-router:test:unit
# 2. Test specific files within package
cd packages/react-router && npx vitest run tests/link.test.tsx
# 3. Test specific functionality
npx vitest run tests/link.test.tsx -t "preloading"- Update relevant docs in
docs/directory - Ensure examples reflect documentation
- Test documentation links and references
- Uses React Router components and hooks
- Supports React Server Components (RSC)
- Examples include React Query integration
- Uses Solid Router components and primitives
- Supports Solid Start for full-stack applications
- Examples include Solid Query integration
- Main Documentation: https://tanstack.com/router
- GitHub Repository: https://github.com/TanStack/router
- Discord Community: https://discord.com/invite/WrRKjPJ