ParamType class implements custom parameter types, and ParamTypes manages the registry of built-in and custom types.
ParamType Class
ParamTypeDefinition interface. Created when a parameter type is registered.
Properties
name
pattern
/.*/
raw
true, the parameter value will not be URL-encoded.
dynamic
true, changes to this parameter type’s values will not cause state reload.
inherit
true, parameter values of this type are inherited during transitions.
Default: true
Methods
is()
Tests if a value is compatible with this parameter type.val- The value to checkkey- The parameter name (optional)
true if the value matches the type.
encode()
Encodes a value to a string for the URL.val- The value to encodekey- The parameter name (optional)
decode()
Decodes a string from the URL to a typed value.val- The string to decodekey- The parameter name (optional)
equals()
Determines if two decoded values are equivalent.a- First valueb- Second value
true if the values are equal.
ParamTypes Registry
Methods
type()
Registers or retrieves a parameter type.name- The type namedefinition- The type definition (optional)definitionFn- Injectable function returning a definition (optional)
- If only
nameis specified: the registeredParamTypeorundefined - If
definitionis specified:this(for chaining)
Built-in Types
string
path
string but doesn’t match forward slashes /.
Pattern: /[^/]*/
Example:
query
string.
Example:
hash
# parameter (the URL hash). Behaves like string but with inherit: false.
int
/-?\d+/
Example:
bool
true/false as 1/0.
Pattern: /0|1/
Example:
date
YYYY-MM-DD
Pattern: /[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[1-2][0-9]|3[0-1])/
Example: