📄 tanstack/router/latest/docs/api/file-based-routing

File: file-based-routing.md | Updated: 11/15/2025

Source: https://tanstack.com/router/latest/docs/api/file-based-routing



TanStack

Router v1v1

Search...

+ K

Auto

Log In

TanStack StartRC

Docs Examples GitHub Contributors

TanStack Router

Docs Examples GitHub Contributors

TanStack Query

Docs Examples GitHub Contributors

TanStack Table

Docs Examples Github Contributors

TanStack Formnew

Docs Examples Github Contributors

TanStack DBbeta

Docs Github Contributors

TanStack Virtual

Docs Examples Github Contributors

TanStack Paceralpha

Docs Examples Github Contributors

TanStack Storealpha

Docs Examples Github Contributors

TanStack Devtoolsalpha

Docs Github Contributors

More Libraries

Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide

Documentation

Framework

React logo

React

Version

Latest

Search...

+ K

Menu

Getting Started

Installation Guides

Routing

Guides

API

Integrations

ESLint

Router Examples

Framework

React logo

React

Version

Latest

Menu

Getting Started

Installation Guides

Routing

Guides

API

Integrations

ESLint

Router Examples

On this page

File-Based Routing API Reference

Copy Markdown

TanStack Router's file-based routing is quite flexible and can be configured to suit your project's needs.

Configuration options
---------------------

The following options are available for configuring the file-based routing:

Warning

Do not set the routeFilePrefix, routeFileIgnorePrefix, or routeFileIgnorePattern options, to match any of the tokens used in the File Naming Conventions guide, or you may run into unexpected behavior.

### routesDirectory (required)

This is the path to the directory where the route files are located, relative to the cwd (current working directory).

By default, the value is set to the following and cannot be set to an empty string or undefined.

txt

./src/routes


./src/routes

### generatedRouteTree (required)

This is the path to the file where the generated route tree will be saved, relative to the cwd (current working directory).

By default, the value is set to the following and cannot be set to an empty string or undefined.

txt

./src/routeTree.gen.ts


./src/routeTree.gen.ts

If the disableTypes is set to true, the generated route tree will be saved with the .js extension instead of .ts.

### virtualRouteConfig

This option is used to configure the Virtual File Routes feature. See the "Virtual File Routes" guide for more information.

By default, this value is set to undefined.

### routeFilePrefix

This option is used to identify route files in the route directory. This means that only files that start with this prefix will be considered for routing.

By default, this value is set to `` and as such all files in the route directory will be considered for routing.

### routeFileIgnorePrefix

This option is used to ignore specific files and directories in the route directory. This can be useful if you want to "opt-in" certain files or directories that you do not want to be considered for routing.

By default, this value is set to -.

When using this option, it allows you have structures like this where it let's you co-located related files that are not route files:

txt

src/routes
├── posts
│   ├── -components  // Ignored
│   │   ├── Post.tsx
│   ├── index.tsx
│   ├── route.tsx


src/routes
├── posts
│   ├── -components  // Ignored
│   │   ├── Post.tsx
│   ├── index.tsx
│   ├── route.tsx

### routeFileIgnorePattern

This option is used to ignore specific files and directories in the route directory. It can be used in regular expression format. For example, .((css|const).ts)|test-page will ignore files / directories with names containing .css.ts, .const.ts or test-page.

By default, this value is set to undefined.

### routeToken

As mentioned in the Routing Concepts guide, a layout route is rendered at the specified path, and the child routes are rendered within the layout route. The routeToken is used to identify the layout route file in the route directory.

By default, this value is set to route.

🧠 the following filenames would equal the same runtime URL:

txt

src/routes/posts.tsx -> /posts
src/routes/posts.route.tsx -> /posts
src/routes/posts/route.tsx -> /posts


src/routes/posts.tsx -> /posts
src/routes/posts.route.tsx -> /posts
src/routes/posts/route.tsx -> /posts

### indexToken

As mentioned in the Routing Concepts guide, an index route is a route that is matched when the URL path is exactly the same as the parent route. The indexToken is used to identify the index route file in the route directory.

By default, this value is set to index.

🧠 the following filenames would equal the same runtime URL:

txt

src/routes/posts.index.tsx -> /posts/
src/routes/posts/index.tsx -> /posts/


src/routes/posts.index.tsx -> /posts/
src/routes/posts/index.tsx -> /posts/

### quoteStyle

When your generated route tree is generated and when you first create a new route, those files will be formatted with the quote style you specify here.

By default, this value is set to single.

Tip

You should ignore the path of your generated route tree file from your linter and formatter to avoid conflicts.

### semicolons

When your generated route tree is generated and when you first create a new route, those files will be formatted with semicolons if this option is set to true.

By default, this value is set to false.

Tip

You should ignore the path of your generated route tree file from your linter and formatter to avoid conflicts.

### autoCodeSplitting

This feature is only available if you are using the TanStack Router Bundler Plugin.

This option is used to enable automatic code-splitting for non-critical route configuration items. See the "Automatic Code-Splitting" guide for more information.

By default, this value is set to false.

Important

The next major release of TanStack Router (i.e. v2), will have this value defaulted to true.

### disableTypes

This option is used to disable generating types for the route tree.

If set to true, the generated route tree will not include any types and will be written as a .js file instead of a .ts file.

By default, this value is set to false.

### addExtensions

This option adds file extensions to the route names in the generated route tree.

By default, this value is set to false.

### disableLogging

This option turns off the console logging for the route generation process.

By default, this value is set to false.

### routeTreeFileHeader

This option let's you prepend content to the start of the generated route tree file.

By default, this value is set to:

json

[\
  "/* eslint-disable */",\
  "// @ts-nocheck",\
  "// noinspection JSUnusedGlobalSymbols"\
]


[\
  "/* eslint-disable */",\
  "// @ts-nocheck",\
  "// noinspection JSUnusedGlobalSymbols"\
]

### routeTreeFileFooter

This option let's you append content to the end of the generated route tree file.

By default, this value is set to:

json

[]


[]

### enableRouteTreeFormatting

This option turns on the formatting function on the generated route tree file, which can be time-consuming for large projects.

By default, this value is set to true.

### tmpDir

Atomic file writes (route files and the generated route tree file) are implemented by creating a temporary file first and then renaming it to their actual location.

This config option allows to configure the path of the temp directory that will be used for creating those temporary files. If it is a relative path, it will be resolved to the current working directory. If this value is not set, process.env.TSR_TMP_DIR will be used. If process.env.TSR_TMP_DIR is not set, it will default to .tanstack/tmp relative to the current working directory.

Edit on GitHub

Render Optimizations

Router

Partners Become a Partner

Code RabbitCode Rabbit CloudflareCloudflare AG GridAG Grid NetlifyNetlify NeonNeon WorkOSWorkOS ClerkClerk ConvexConvex ElectricElectric SentrySentry PrismaPrisma StrapiStrapi UnkeyUnkey

scarf analytics