UrlRules API is used to create and manage URL rules. URL rules are a mechanism to respond to specific URL patterns.
Overview
Access theUrlRules API via router.urlService.rules.
Properties
urlRuleFactory
UrlRule objects for common cases.
Methods
when()
Registers a matcher and handler for custom URL handling.matcher- A pattern to match (string compiled as UrlMatcher, or RegExp)handler- The redirect path or handler functionoptions- Optional configuration (e.g.,{ priority: 1 })
UrlRule
Example (string redirect):
otherwise()
Defines the state, URL, or behavior to use when no other rule matches.handler- The URL path to redirect to, a state definition, or a handler function
initial()
Defines the initial state, path, or behavior when the app starts.handler- The initial state or URL path, or a handler function
"" or "/".
Example (state):
rule()
Manually adds a URL rule.rule- AUrlRuleobject
StateDeclaration.url or when(). This API can be used directly for more control.
Example:
removeRule()
Removes a previously registered rule.rule- The rule that was previously registered
rules()
Gets all registered rules.otherwise rule if defined)
sort()
Defines URL rule priorities using a custom comparison function.compareFn- A function that compares twoUrlRuleobjects (optional)
- Explicit priority
- Rule type (STATE: 4, URLMATCHER: 4, REGEXP: 3, RAW: 2, OTHER: 1)
UrlMatcherspecificity- Registration order