Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
deckardger avatar

Tanstack Router Best Practices

  • 5.8k installs
  • 205 repo stars
  • Updated April 3, 2026
  • deckardger/tanstack-agent-skills

tanstack-router-best-practices teaches type-safe TanStack Router patterns for React routing, loaders, search params, and navigation.

About

The tanstack-router-best-practices skill delivers comprehensive guidelines for implementing TanStack Router in React applications with emphasis on type safety, data loading, navigation, and route organization. Apply when setting up application routing, creating routes and layouts, implementing search parameter handling, configuring data loaders, enabling code splitting, integrating TanStack Query, or refactoring navigation patterns. Rule categories span CRITICAL type safety and route organization, HIGH router config, data loading, search params, and error handling, plus MEDIUM navigation, code splitting, and preloading, and LOW route context dependency injection. Quick reference prefixes include ts for global router inference and route context typing, org for file-based routing and pathless layouts, load for loaders with loaderDeps, ensureQueryData, deferred data, and parallel loading, search for validated params with middleware and serializers, nav for Link components and route masks, split for lazy routes and autoCodeSplitting, preload for intent-based loading, and ctx for root context injection. Each rule file documents explanation, bad examples, good examples, and contextual w.

  • Prioritizes CRITICAL type safety and route organization rules with named prefixes.
  • Covers loaders, ensureQueryData, deferred data, and TanStack Query integration patterns.
  • Documents validated search params, middleware, serializers, and sensible defaults.
  • Guides navigation with Link, active states, route masks, and programmatic navigate.
  • Includes code splitting via lazy routes, preloading, and route context injection.

Tanstack Router Best Practices by the numbers

  • 5,832 all-time installs (skills.sh)
  • +108 installs in the week ending Aug 5, 2026 (Skillselion tracking)
  • Ranked #88 of 2,245 Frontend Development skills by installs in the Skillselion catalog
  • Security screen: MEDIUM risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
At a glance

tanstack-router-best-practices capabilities & compatibility

Capabilities
type safety rules for router registration and ro · route organization with file based routing and p · data loading patterns with loaders, deferred dat · search param validation, middleware, and custom · navigation, code splitting, preloading, and erro
Use cases
frontend · refactoring
From the docs

What tanstack-router-best-practices says it does

Comprehensive guidelines for implementing TanStack Router patterns in React applications.
SKILL.md
Integrating with TanStack Query
SKILL.md
npx skills add https://github.com/deckardger/tanstack-agent-skills --skill tanstack-router-best-practices

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs5.8k
repo stars205
Security audit3 / 3 scanners passed
Last updatedApril 3, 2026
Repositorydeckardger/tanstack-agent-skills

How do I implement TanStack Router correctly with type-safe loaders, search params, and navigation?

Implement type-safe TanStack Router patterns for React apps with loaders, search params, navigation, and TanStack Query integration.

Who is it for?

React teams adopting or refining TanStack Router with complex routing and TanStack Query integration.

Skip if: Skip for backend-only APIs, non-React frameworks, or apps without client-side routing needs.

When should I use this skill?

Setting up routing, creating routes and layouts, search param handling, loaders, code splitting, or refactoring navigation.

What you get

Maintainable route trees with validated URL state, optimized data loading, and fewer routing runtime errors.

  • Typed root route context setup
  • Refactored route files without global client imports

Files

SKILL.mdMarkdownGitHub ↗

TanStack Router Best Practices

Comprehensive guidelines for implementing TanStack Router patterns in React applications. These rules optimize type safety, data loading, navigation, and code organization.

When to Apply

  • Setting up application routing
  • Creating new routes and layouts
  • Implementing search parameter handling
  • Configuring data loaders
  • Setting up code splitting
  • Integrating with TanStack Query
  • Refactoring navigation patterns

Rule Categories by Priority

PriorityCategoryRulesImpact
CRITICALType Safety4 rulesPrevents runtime errors and enables refactoring
CRITICALRoute Organization5 rulesEnsures maintainable route structure
HIGHRouter Config1 ruleGlobal router defaults
HIGHData Loading6 rulesOptimizes data fetching and caching
HIGHSearch Params5 rulesEnables type-safe URL state
HIGHError Handling1 ruleHandles 404 and errors gracefully
MEDIUMNavigation5 rulesImproves UX and accessibility
MEDIUMCode Splitting3 rulesReduces bundle size
MEDIUMPreloading3 rulesImproves perceived performance
LOWRoute Context3 rulesEnables dependency injection

Quick Reference

Type Safety (Prefix: ts-)

  • ts-register-router — Register router type for global inference
  • ts-use-from-param — Use from parameter for type narrowing
  • ts-route-context-typing — Type route context with createRootRouteWithContext
  • ts-query-options-loader — Use queryOptions in loaders for type inference

Router Config (Prefix: router-)

  • router-default-options — Configure router defaults (scrollRestoration, defaultErrorComponent, etc.)

Route Organization (Prefix: org-)

  • org-file-based-routing — Prefer file-based routing for conventions
  • org-route-tree-structure — Follow hierarchical route tree patterns
  • org-pathless-layouts — Use pathless routes for shared layouts
  • org-index-routes — Understand index vs layout routes
  • org-virtual-routes — Understand virtual file routes

Data Loading (Prefix: load-)

  • load-use-loaders — Use route loaders for data fetching
  • load-loader-deps — Define loaderDeps for cache control
  • load-ensure-query-data — Use ensureQueryData with TanStack Query
  • load-deferred-data — Split critical and non-critical data
  • load-error-handling — Handle loader errors appropriately
  • load-parallel — Leverage parallel route loading

Search Params (Prefix: search-)

  • search-validation — Always validate search params
  • search-type-inheritance — Leverage parent search param types
  • search-middleware — Use search param middleware
  • search-defaults — Provide sensible defaults
  • search-custom-serializer — Configure custom search param serializers

Error Handling (Prefix: err-)

  • err-not-found — Handle not-found routes properly

Navigation (Prefix: nav-)

  • nav-link-component — Prefer Link component for navigation
  • nav-active-states — Configure active link states
  • nav-use-navigate — Use useNavigate for programmatic navigation
  • nav-relative-paths — Understand relative path navigation
  • nav-route-masks — Use route masks for modal URLs

Code Splitting (Prefix: split-)

  • split-lazy-routes — Use .lazy.tsx for code splitting
  • split-critical-path — Keep critical config in main route file
  • split-auto-splitting — Enable autoCodeSplitting when possible

Preloading (Prefix: preload-)

  • preload-intent — Enable intent-based preloading
  • preload-stale-time — Configure preload stale time
  • preload-manual — Use manual preloading strategically

Route Context (Prefix: ctx-)

  • ctx-root-context — Define context at root route
  • ctx-before-load — Extend context in beforeLoad
  • ctx-dependency-injection — Use context for dependency injection

How to Use

Each rule file in the rules/ directory contains: 1. Explanation — Why this pattern matters 2. Bad Example — Anti-pattern to avoid 3. Good Example — Recommended implementation 4. Context — When to apply or skip this rule

Full Reference

See individual rule files in rules/ directory for detailed guidance and code examples.

Related skills

How it compares

Use tanstack-router-best-practices for TanStack Router context architecture; use a general React routing guide when the stack is not TanStack Router.

FAQ

What does tanstack-router-best-practices do?

tanstack-router-best-practices teaches type-safe TanStack Router patterns for React routing, loaders, search params, and navigation.

When should I use tanstack-router-best-practices?

Setting up routing, creating routes and layouts, search param handling, loaders, code splitting, or refactoring navigation.

Is this skill safe to install?

Review the Security Audits panel on this page before installing in production.

Frontend Developmentfrontendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.