Skip to main content

ESLint Plugin

The TanStack Router ESLint plugin provides linting rules to catch common mistakes and enforce best practices when using TanStack Router.

Installation

Setup

Flat Config (ESLint 9+)

For ESLint 9+ using the flat config format:
Or configure manually:

Legacy Config (ESLint 8)

For ESLint 8 using .eslintrc.js:
Or configure manually:

Rules

The plugin includes the following rules:

create-route-property-order

Severity: warn (in recommended config) Ensures correct order of inference-sensitive properties for createRoute functions. TanStack Router uses TypeScript’s type inference, and the order of properties in route configurations affects type inference. This rule enforces the correct order. Incorrect:
Correct:
Auto-fix: This rule provides automatic fixes to reorder properties correctly. Applies to:
  • createRoute()
  • createRootRoute()
  • createFileRoute()()
  • createRootRouteWithContext()()
  • createLazyRoute()()
  • createLazyFileRoute()()

route-param-names

Severity: error (in recommended config) Ensures route param names are valid JavaScript identifiers. Route parameters are extracted and used as object properties in your code. They must be valid JavaScript identifiers to avoid runtime errors. Incorrect:
Correct:
Valid identifier rules:
  • Must start with a letter, underscore (_), or dollar sign ($)
  • Can contain letters, numbers, underscores, and dollar signs
  • Cannot contain hyphens, dots, or other special characters
  • Cannot start with a number
  • Regex pattern: /[a-zA-Z_$][a-zA-Z0-9_$]*/
Applies to:
  • createRoute({ path: '...' })
  • createFileRoute('...')(...)
  • createRootRoute({ path: '...' })
  • createLazyRoute({ path: '...' })
  • createLazyFileRoute('...')(...)

Configuration

You can customize rule severity in your ESLint config:

Flat Config

Legacy Config

Framework Support

The plugin automatically detects TanStack Router imports from:
  • @tanstack/react-router
  • @tanstack/solid-router
  • @tanstack/vue-router
  • Any custom package with router in the name
Rules only apply when they detect you’re using TanStack Router.

Examples

Full Flat Config Example

Full Legacy Config Example

With React and TypeScript

IDE Integration

VS Code

Install the ESLint extension. The plugin’s auto-fix for create-route-property-order will work with VS Code’s “Fix on Save” feature:

IntelliJ IDEA / WebStorm

ESLint integration is built-in. Enable it in: Settings → Languages & Frameworks → JavaScript → Code Quality Tools → ESLint

Troubleshooting

Rules Not Running

If rules aren’t running, check:
  1. ESLint is installed and configured correctly
  2. The plugin is added to your ESLint config
  3. Your files are included in ESLint’s file patterns
  4. You’re importing from a TanStack Router package

False Positives

If you get warnings/errors when not using TanStack Router:
  1. The plugin should auto-detect imports
  2. Make sure you’re not using function names like createRoute without importing from TanStack Router
  3. If needed, disable specific rules for certain files using overrides

Auto-fix Not Working

For create-route-property-order, auto-fix should work automatically. If it doesn’t:
  1. Check your ESLint version is compatible
  2. Make sure your IDE’s ESLint integration is enabled
  3. Try running eslint --fix from the command line

TypeScript Errors

The ESLint plugin is independent of TypeScript. If you have TypeScript errors after auto-fixing:
  1. The auto-fix may have revealed existing type issues
  2. Run tsc --noEmit to check for type errors
  3. The correct property order often improves type inference

Versioning

The plugin follows TanStack Router’s versioning. Use matching major versions:
  • @tanstack/router-plugin@1.x@tanstack/eslint-plugin-router@1.x
  • @tanstack/react-router@1.x@tanstack/eslint-plugin-router@1.x

Contributing

To suggest new rules or report issues:
  1. Visit the TanStack Router GitHub repository
  2. Search existing issues
  3. Create a new issue with:
    • Description of the problem
    • Example code that should be caught
    • Suggested error message

Further Reading