Routing#
In Kiln, the file tree is the route table. Each file under app/pages becomes a URL, and you never write a list of routes. This guide explains how file names turn into URLs, how dynamic segments work, how route groups affect layouts without changing URLs, and how Kiln decides which route wins when two could match.
From files to URLs#
The path of a file, relative to app/pages, without its extension, becomes the URL path:
| File | URL |
|---|---|
app/pages/index.tsx | / |
app/pages/about.tsx | /about |
app/pages/blog/index.tsx | /blog |
app/pages/blog/launch.tsx | /blog/launch |
app/pages/docs/guide.md | /docs/guide |
The name index maps to its folder. So blog/index.tsx and blog.tsx both produce /blog, but you should use one form per URL. Two files that map to the same URL cause a build error: Route conflict: ….
Dynamic segments#
Wrap a segment name in square brackets to capture it:
app/pages/blog/[slug].tsx -> /blog/:slug
app/pages/users/[id]/posts.tsx -> /users/:id/postsThe captured value arrives in two places: the params object passed to the loader and action, and the params prop passed to the page component.
// app/pages/users/[id].tsx
export async function loader({ params }: { params: Record<string, string> }) {
return { id: params.id };
}
export default function User({ params, data }: { params: Record<string, string>; data: { id: string } }) {
return <h1>User {data.id}</h1>;
}Captured values are decoded from the URL, so /blog/hello%20world gives params.slug as hello world.
Catch-all segments#
Wrap a name in [...name] to capture the rest of the URL:
app/pages/docs/[...path].tsx -> /docs/*path/docs/a/b/c gives params.path the value a/b/c. A catch-all matches one or more segments. It does not match /docs on its own, so add docs/index.tsx if you want that URL too.
A catch-all must be the last segment of the file name. Kiln treats it as the final part of the route.
Route groups#
Wrap a folder name in parentheses to group pages without adding a URL segment:
app/pages/(marketing)/_layout.tsx a layout for the group
app/pages/(marketing)/pricing.tsx -> /pricing
app/pages/(marketing)/about.tsx -> /aboutA route group is useful for giving a set of pages their own layout. It never changes the URL. Groups can nest, and each group's _layout applies to the pages inside it. See Layouts.
Priority#
Routes are sorted once, when the table is built. Kiln compares routes segment by segment. For each segment position:
- A static segment beats a dynamic segment.
- A dynamic segment beats a catch-all.
- A route that ends beats a route that continues.
So with these files:
app/pages/blog/new.tsx
app/pages/blog/[slug].tsx
app/pages/[...rest].tsxthe URL /blog/new goes to new.tsx, /blog/hello goes to [slug].tsx, and /blog/a/b goes to [...rest].tsx.
The matcher checks routes in this sorted order and returns the first match. You do not need to think about the order in which files were created.
Special files#
Files whose names begin with an underscore are never routes. Kiln uses these names:
| Name | Purpose |
|---|---|
_layout.tsx | Layout for the folder and everything below it. See Layouts. |
_error.tsx | Page shown when a page throws. See Errors. |
_not-found.tsx | Page shown when no route matches. See Errors. |
Render mode suffixes#
A .server or .client suffix before the extension sets the render mode and is removed from the URL:
app/pages/about.server.tsx -> /about, rendered on the server only
app/pages/dashboard.client.tsx -> /dashboard, rendered in the browser onlySee Rendering modes.
Matching rules#
- Matching uses the URL path only. The query string is ignored by the route match. Loaders can read it from
request.url. - Trailing slashes do not matter.
/aboutand/about/reach the same page. - Matching is case-sensitive.
/Aboutdoes not reachabout.tsx. - A
HEADrequest renders the page and returns no body.
Checking your routes#
Print the route table with the CLI:
bunx kiln routesEach line shows the URL pattern, the render mode, and the file. Use it to confirm how a new file maps before you rely on it.
Route conflicts#
If two files map to the same pattern, the scanner stops with an error that names both files:
Route conflict: blog/index.tsx and blog.tsx both map to /blogRename or move one of them. API routes have the same rule, under api/.

