Skip to main content

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 *:
You can destructure the catchall param:

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 be undefined, 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 ?: