Skip to main content

TemplateRoute

Matches a concrete route string against parameterized route templates.

Instances keep the original route in route and expose matched template parameters as dynamic attributes after a successful call to match(). Parameter attributes captured by a previous match are reset to None before each new matching attempt, preventing stale values from leaking between checks.

Only the path of the route is matched; a query string and a # fragment are ignored, so /books/42?tab=reviews matches /books/:id with id set to "42". Read query string parameters with Page.query.

Properties

Methods

  • match - Tries to match the path of this instance route against a route template.

Properties​

routeinstance-attribute​

Methods​

match​

match(route_template: str) -> bool

Tries to match the path of this instance route against a route template.

The template is compiled with repath.pattern() and matched against the route without its query string and fragment. If matching succeeds, named parameters are stored and also assigned as attributes on this object (for example, self.user_id). If matching fails, previously captured attributes remain cleared.

Parameters:

  • route_template (str) - Route template in a format supported by repath.pattern().

Returns:

  • bool - True if the route matches the template; otherwise False.