A path param is the part of a web address that changes from page to page, such as the name in /hello/Asha. In TanStack Start, you make one by putting a $ in a route file’s name, and you read its value with Route.useParams().
This post builds a greeting page that says hello to whatever name is in the address.
Syntax
// src/routes/<folder>/$<param>.tsx
export const Route = createFileRoute('/<folder>/$<param>')({
component: <Component>,
})
function <Component>() {
const { <param> } = Route.useParams()
// use <param> in the page
}
$<param>in the file name: the$makes that part of the address a path param, and<param>is the name its value gets. It matches the text up to the next/.'/<folder>/$<param>': the route’s path. TanStack Start writes it for you from the file’s place and name.Route.useParams(): gives the component an object with the route’s path params, such as{ name: 'Asha' }. The values are always text.<Component>: the React component that shows the page.
TanStack Router’s Path Params guide (opens in a new tab) describes every option.
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 hello, and in it a file named $name.tsx:
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/hello/$name')({
component: Hello,
})
function Hello() {
const { name } = Route.useParams()
return <h1>Hello, {name}!</h1>
}
- The file’s place and name give the route the path
/hello/$name:/hello/followed by any name. const { name } = Route.useParams()reads the param, and the heading shows it.
Step 2: Open the Page
Start the dev server with npm run dev, then open http://localhost:3000/hello/Asha:

Change the name in the address, and the greeting changes with it. Characters that an address can’t hold as they are arrive decoded: http://localhost:3000/hello/Mira%20Kale, where %20 stands for a space, shows this:

Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Naming the file name.tsx, without the $ | The route matches only the address /hello/name | Start the file name with $ |
Treating the value as a number, as in /items/2 | The value is the text "2" | Compare it with text, or turn it into a number with Number() |
Expecting one param to hold a slash, as in /hello/Mira/Kale | The route doesn’t match, because a path param stops at the next / | Use one path param for each part of the address |
FAQ
Can a loader read the param? Yes. A route’s loader gets the same values as params, such as params.name (Path Params (opens in a new tab), “Path Params in Loaders”).
Can a route have more than one path param? Yes. Each $ part of the path is its own param, so a route with the path /authors/$authorId/books/$bookId gets both authorId and bookId.
Conclusion
A $ in a route file’s name makes a path param, and Route.useParams() reads its value. One file then answers every address of that shape.
Additional Resources
- Path Params (opens in a new tab) in the TanStack Router docs
- Routing Concepts (opens in a new tab), with dynamic route segments
- useParams (opens in a new tab) reference
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