Router Docs
Core Routing
Navigation & URL State
Data & Rendering
Router Configuration
Integrations
AI/LLM: This documentation page is available in plain markdown format at/router/latest/docs/routing/route-matching.md
Core Routing
Route Matching
Route matching follows a consistent and predictable pattern. This guide will explain how route trees are matched.
When TanStack Router processes your route tree, all of your routes are automatically sorted to match the most specific routes first. This means that regardless of the order your route tree is defined, routes will always be sorted in this order:
- Index Route
- Static Routes (most specific to least specific)
- Dynamic Routes (longest to shortest)
- Splat/Wildcard Routes
Consider the following pseudo route tree:
plaintext
Root
- blog
- $postId
- /
- new
- /
- *
- about
- about/usAfter sorting, this route tree will become:
plaintext
Root
- /
- about/us
- about
- blog
- /
- new
- $postId
- *This final order represents the order in which routes will be matched based on specificity.
Using that route tree, let's follow the matching process for a few different URLs:
- /blogplaintext
Root ❌ / ❌ about/us ❌ about ⏩ blog ✅ / - new - $postId - * - /blog/my-postplaintext
Root ❌ / ❌ about/us ❌ about ⏩ blog ❌ / ❌ new ✅ $postId - * - /plaintext
Root ✅ / - about/us - about - blog - / - new - $postId - * - /not-a-routeplaintext
Root ❌ / ❌ about/us ❌ about ❌ blog - / - new - $postId ✅ *