Router

ui.router is a component that matches the current URL path against provided routes and renders the matching route’s element. Use it with route to define hierarchical navigation structures.

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

Router Options

Build a simple app with a router, nested routes, route parameters, and a fallback “not found” page.

This produces the following route table:

URL PathMatched ElementParams
/dashboard{}
/usersuser_page{}
/users/42user_page{"user_id": "42"}
/anything-elsenot_found{"*": "anything-else"}

Recommendations

  1. Include a wildcard route (path="*") as a fallback so unmatched paths render a meaningful “not found” message instead of an error.
  2. Use an index=True route to define what renders at the exact parent path (such as a landing page at /).
  3. Use use_params inside routed components to access route parameters, and use_path for the current path.
  4. Use use_navigate or link with to to navigate between routes.

API Reference

Router

Match the current URL path against the provided routes and render the matching route's element.

Returns: Any The element for the matched route wrapped in a params context, or an error element if no route matches.

ParametersTypeDefaultDescription
*routes_RouteRoute definitions to match against.

Matching behavior

  1. Static segments are preferred over parameterized segments.
  2. Longer matches (more segments) are preferred over shorter ones.
  3. Wildcard routes (*) have the lowest priority.
  4. Optional segments are matched if present but do not prevent a match if absent.
  5. Index routes match only the exact parent path.
  6. If no route matches, the router renders an error.

Route

Define a route mapping a URL path pattern to a component.

Returns: _Route A _Route instance, to be consumed by the router component.

ParametersTypeDefaultDescription
*children_RouteChild routes for nested routing.
pathstr |
None
NoneThe path segment appended to the parent route's path. Variables are defined with {var_name} syntax and extracted as route params. Optional variables use {var_name?} syntax. Wildcard segments are supported with "*". Leading / is optional. Mutually exclusive with index.
elementCallable[..., Any] |
None
NoneThe component function to render when this route matches.
indexboolFalseIf True, this route matches the parent's exact path (like an index route). Mutually exclusive with path.

Path patterns

  • {var_name}: Required dynamic segment
  • {var_name?}: Optional dynamic segment (matches zero or one segments)
  • *: Wildcard, matches any remaining path segments
  • Static text: Exact match

See use_params for more details on route parameters.

Child paths are appended to parent paths. For example, ui.route(ui.route(path="{user_id}"), path="users") produces /users/{user_id}.