A catch-all route matches every address that starts a certain way, however many parts follow, such as /files/report.pdf and /files/photos/cat.jpg. TanStack Start calls it a splat route: a route file named $.tsx, whose params hold the rest of the address under _splat.
This post builds a page that shows which file the address asked for.
Syntax
// src/routes/<folder>/$.tsx
export const Route = createFileRoute('/<folder>/$')({
component: <Component>,
})
function <Component>() {
const { _splat } = Route.useParams()
// _splat holds the rest of the address
}
$.tsx: a file named only$makes a splat route. It catches everything after/<folder>/, slashes included._splat: the name the rest of the address gets in the route’s params.<Component>: the React component that shows the page.
See “Splat / Catch-All Routes” in TanStack Router’s Routing Concepts (opens in a new tab).
The example is a small TanStack Start app with only a home page, set up as in How to Build a TanStack Start App from Scratch Without the CLI. Any TanStack Start app works the same way.
Step 1: Create the Route File
In src/routes, create a folder named files, and in it a file named $.tsx:
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/files/$')({
component: Files,
})
function Files() {
const { _splat } = Route.useParams()
return <p>You asked for: {_splat}</p>
}
const { _splat } = Route.useParams() reads the rest of the address, and the page shows it.
Step 2: Open a Few Addresses
Start the dev server with npm run dev, then open http://localhost:3000/files/photos/cat.jpg:

The route caught both parts after /files/, with the slash between them. One part works too: http://localhost:3000/files/report.pdf shows this:

Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Using $name.tsx when the value can contain slashes | /files/photos/cat.jpg doesn’t match, because a path param stops at the next / | Use a splat route, $.tsx |
Reading the value from params['*'] | It works in TanStack Router 1 only to stay compatible, and version 2 removes it | Read _splat |
FAQ
What does /files itself show? The splat route matches it too, with _splat as empty text, so the page shows You asked for: with nothing after it.
Are spaces in the address decoded? Yes. /files/my%20notes/day%201.txt gives my notes/day 1.txt.
Why $ and not *? TanStack Router’s docs explain that * doesn’t work well in file names and command-line tools, so it uses $ (Routing Concepts (opens in a new tab)).
Conclusion
A file named $.tsx catches every address under its folder, and _splat holds the rest of the address, slashes and all.
Additional Resources
- Routing Concepts (opens in a new tab) in the TanStack Router docs, with “Splat / Catch-All Routes”
- Path Params (opens in a new tab)
Related
- TanStack Start Tutorial — Part 4: Dynamic Routes and Path Params
- TanStack Start Tutorial for Beginners, every part of the series
TanStack, React and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by TanStack.
0 comments