route()
Registers a route pattern with one or more activities or factory functions.
route<P extends string>(
pattern: P,
...args: ActivityRouter.RouteArg<P>[]
): this;
Notes
- When the navigation path matches the pattern, all provided activities are activated and added to the active list.
- When the path no longer matches, activities are deactivated. Activities passed by reference remain attached; factory-created activities are removed (and unlinked).
- Pattern segments starting with
:are treated as parameters (e.g.users/:userId). - A
*segment at the end matches any remaining path segments; the matched portion is available as thepathparameter. A bare*matches any path including the root, withpathset to an empty string when no segments remain. - Factory functions receive the extracted parameters as an argument and may return an Activity instance, or undefined. Returning no activity skips activation for that route arg. If a factory throws, the error propagates to the global error handler.
- Routes are matched by specificity (most specific match wins). Static segments take priority over parameterized segments, longer patterns take priority over shorter ones, and non-wildcard routes take priority over wildcard routes. Registration order is used as a tiebreaker when routes have equal specificity.
Parameters
- pattern — The route pattern to match (e.g.
"users/:userId") - args — One or more Activity instances or factory functions
Errors
Throws if the pattern is invalid (leading/trailing slashes, empty segments, dots, bare :, or * not at end)
Related
class ActivityRouter
A class that manages activation and deactivation of activities, with support for path-based routing.
