Skip to content

File-based routing

The directory tree under app/pages is the route table.

FileURLMode
index.tsx/universal
about.server.tsx/aboutserver
blog/[slug].tsx/blog/:sluguniversal
docs/[...path].tsx/docs/*pathuniversal
(marketing)/pricing.tsx/pricinguniversal

Rules

  • index maps to its folder. blog/index.tsx serves /blog.
  • [name] is a dynamic segment. [...name] is a catch-all.
  • (group) folders share layouts and organize files, but never appear in the URL.
  • Files whose names start with _ are never routes. _layout.tsx wraps the pages beside it and below it.
  • Two files that resolve to the same URL stop the build with a conflict error.

Priority

Static segments beat dynamic segments, and dynamic segments beat catch-alls. /blog/new wins over /blog/[slug].

Why not a config file

A central route table drifts from the files it describes. A file-based table cannot drift, because the files are the table.