useParams
Returns an object of key/value pairs of the dynamic params from the current URL that were matched by the routes. Child routes inherit all params from their parent routes.Signature
Parameters
None.Returns
Record<string, string | undefined>
An object containing the URL parameters from the matched route. All values are strings or
undefined.Usage
Basic usage
Given a route pattern like/posts/:postId:
Multiple params
Patterns can have multiple params:Catchall params
Catchall params are defined with*:
Named catchall params
You can also name catchall params:Using in loaders
Params are available in route loaders:Parent route params
Child routes inherit all params from parent routes:Type Safety
Generic type parameter
You can provide a type for better type checking:With route loader types
In Framework mode, types are automatically generated:Runtime validation
Since params can beundefined, validate them at runtime:
Common Patterns
Convert to number
Params are always strings. Convert to numbers as needed:URL decode params
Params are automatically URL-decoded:Optional params
Make params optional with?:
Related
useLocation- Access current locationuseSearchParams- Work with search paramsuseLoaderData- Access loader dataloader- Route loader function