Capítulo 26 de 57
Path params ($name) match a single URL segment up to the next / and expose it as a typed, named value in loader, beforeLoad, and components via Route.useParams(); TanStack Router also supports prefixes/suffixes, optional params, and custom parse/stringify/priority logic for advanced matching.
$paramName: Declares a dynamic segment; valid anywhere in a path ($postId, about/$name, team/$teamId). Matches only up to the next /, so child routes can continue the hierarchy.params in loader/beforeLoad: Both receive a params object keyed by param name with string values parsed from the URL (e.g. visiting /blog/123 on /posts/$postId gives { postId: '123' }).Route.useParams(): Typed hook to read params inside a route's own component.useParams({ strict: false }): Reads params from any component in the app, outside a specific route's context, at the cost of losing strict typing.params.parse / params.stringify / params.priority: Custom per-route param transformation. parse can return false to reject a candidate route (falling through to the next match, e.g. a numeric-only $postId route falling back to a $slug route); priority (default 0, higher tried first) controls ordering only among competing routes that use params.parse; static routes still always match before dynamic/optional/wildcard ones regardless of priority. parse must be deterministic/side-effect-free, it may run more than once during route planning.prefix{$param}suffix): Wrap the param name in {} and place literal text outside the braces, e.g. post-{$postId} or {$fileName}[.]txt (bracket-escaped dot). Combinable with splat routes too.{-$param}): See Ch 15/21; in this chapter covered in depth including navigation (params: {} inherits, params: { x: undefined } removes), loaders/beforeLoad receiving possibly-undefined values, and i18n locale-prefix routing patterns (/{-$locale}/about).pathParamsAllowedCharacters: Router option controlling which extra URI-valid characters (beyond default encodeURIComponent escaping) are allowed unescaped in params, e.g. ['@']. Allowed set: ; : @ & = + $ ,.export const Route = createFileRoute('/posts/$postId')({
params: {
priority: 10,
parse: ({ postId }) => {
if (!/^\d+$/.test(postId)) return false
return { postId: Number(postId) }
},
stringify: ({ postId }) => ({ postId: String(postId) }),
},
})
$slug-style fallback route when the raw param isn't numeric.params.parse/stringify pair to coerce and reverse-coerce types (e.g. numbers).params.priority only breaks ties between routes that both use params.parse; it never overrides the base specificity order (static > dynamic > splat) from Ch 17.{$param} with surrounding literal text) and optional params ({-$param}) both extend beyond simple $param segments to express more precise URL patterns without extra route nesting.pathParamsAllowedCharacters sparingly and deliberately, changing default escaping can affect matching/security of adjacent segments.$ token and {-$param} optional syntax used throughout this chapter.params.priority operates within.params is passed to Link/navigate.{-$locale} prefix pattern shown here.