Capítulo 21 de 57
File-based routing depends on a small, precise set of filename tokens and prefixes/suffixes; getting these right is what makes route generation produce the intended route tree.
__root.tsx: The mandatory root route filename, must live at the root of the configured routesDirectory.. Separator: Denotes nesting in flat-file routes, e.g. blog.post.tsx is generated as a child of blog.$ Token: Marks a parameterized route segment, extracting that URL part into params (e.g. posts.$postId.tsx)._ Prefix: Marks a pathless layout route; excluded from URL matching for children but still wraps them._ Suffix: Excludes a route from being nested under any parent route (non-nested route), e.g. posts_.$postId.edit.tsx.- Prefix: Excludes files/folders from the route tree entirely; useful to colocate non-route logic (components, helpers) inside route folders without it becoming a route.(folder) Route Group: A folder name wrapped in parentheses is purely organizational and does not appear in the URL path.[x] Escaping: Square brackets escape characters that would otherwise have routing meaning, e.g. script[.]js.tsx → /script.js, api[.]v1.tsx → /api.v1.index Token: A segment ending in index (before extensions) matches its parent route exactly; configurable via the indexToken option (string or regex)..route.tsx File Type: When using directories, a route suffix file (e.g. blog/post/route.tsx or blog.post.route.tsx) is used as the route file for that directory's path; configurable via the routeToken option.Filename Route Path Component Output
posts.$postId.tsx /posts/$postId <Root><Posts><Post>
Filename Route Path Component Output
_app.tsx (wraps children, no path)
_app.a.tsx /a <Root><App><A>
_app.b.tsx /b <Root><App><B>
$ token producing a dynamic segment, and the _ prefix producing a pathless layout that wraps /a and /b without adding its own URL segment.indexToken, routeToken options), so a project can deviate from the defaults documented here if needed.- prefix (exclude from routing) and (folder) route groups (exclude from URL only) solve two different problems: the former hides files from the route tree entirely, the latter only hides a directory from the URL while keeping its children as routes.[x]) is the way to produce filenames containing literal dots or other routing-significant characters, e.g. for /script.js or /api.v1 style URLs.$ token.