use_params

use_params is a hook that returns the route parameters extracted by the nearest ancestor router.

Note

Deephaven and all custom components share the path. Avoid using routers, the path, path parameters, and navigation in shared components to prevent conflicts. Do not use the route segment /-/ in your application path as it is reserved for internal use by Deephaven.

Example

Parameters with Navigation

Use use_params together with use_path and use_navigate to build a simple user profile page that extracts a required user_id parameter and an optional section parameter from the URL, validates them, and provides navigation buttons to update the parameters.

Route Parameter Patterns

Route parameters are defined by {var_name} segments in route paths:

  • {user_id} matches a required segment and extracts it as "user_id" in the params dict.
  • {tab?} matches an optional segment. The parameter is not included if the segment is missing.
  • * matches any remaining path. The value is available as the "*" key.

See router for more details on defining routes and path patterns.

Recommendations

  1. Validate and parse route parameters as needed since they are always returned as strings and users can manipulate the URL to include unexpected values.
  2. Use use_path to read the full matched path, or use_query_params for query string values. use_params only returns route segment parameters.

API Reference

Route parameters are defined by curly-braced segments in route paths.

Returns: dict[str, str] A dictionary mapping parameter names to their matched string values. Returns an empty dict if no router ancestor exists.