new Route(name, pathExpression, controller, view, options)
Initializes the route.
Parameters:
Name | Type | Description |
---|---|---|
name |
string | The unique name of this route, identifying it among the rest of the routes in the application. |
pathExpression |
string | A path expression specifying the URL path
part matching this route (must not contain a query string),
optionally containing named parameter placeholders specified as
|
controller |
string | The full name of Object Container alias identifying the controller associated with this route. |
view |
string | The full name or Object Container alias identifying the view class associated with this route. |
options |
Object | The route additional options. |
Members
-
_controller :string
-
The full name of Object Container alias identifying the controller associated with this route.
Type:
- string
-
_hasParameters :boolean
-
Set to
true
if this route contains parameters in its path.Type:
- boolean
-
_matcher :RegExp
-
A regexp used to match URL path against this route and extract the parameter values from the matched URL paths.
Type:
- RegExp
-
_name :string
-
The unique name of this route, identifying it among the rest of the routes in the application.
Type:
- string
-
_options :Object
-
The route additional options.
Type:
- Object
-
_parameterNames :Array.<string>
-
The names of the parameters in this route.
Type:
- Array.<string>
-
_pathExpression :string
-
The original URL path expression from which this route was created.
Type:
- string
-
_trimmedPathExpression :string
-
The path expression with the trailing slashes trimmed.
Type:
- string
-
_view :React.Component
-
The full name or Object Container alias identifying the view class associated with this route.
Type:
- React.Component
Methods
-
_checkOptionalParamsOrder(allMainParams)
-
Check if all optional params are below required ones
Parameters:
Name Type Description allMainParams
array.<string> Returns:
- Type
- boolean
-
_checkParametersOrder(clearedPathExpr)
-
Check if main parametres have correct order. It means that required param cannot follow optional one.
Parameters:
Name Type Description clearedPathExpr
string The cleared URL path (removed first and last slash, ...).
Returns:
Returns TRUE if order is correct.
- Type
- Bool
-
_cleanOptParamName(paramName)
-
Returns optional param name without "?"
Parameters:
Name Type Description paramName
string Full param name with "?"
Returns:
Strict param name without "?"
- Type
- string
-
_cleanUnusedOptionalParams(path)
-
Remove unused optional param placeholders in path.
Parameters:
Name Type Description path
string Returns:
New path.
- Type
- string
-
_compileToRegExp(pathExpression)
-
Compiles the path expression to a regular expression that can be used for easier matching of URL paths against this route, and extracting the path parameter values from the URL path.
Parameters:
Name Type Description pathExpression
string The path expression to compile.
Returns:
The compiled regular expression.
- Type
- RegExp
-
_decodeURIParameter(parameterValue)
-
Decoding parameters.
Parameters:
Name Type Description parameterValue
string Returns:
decodedValue
- Type
- string
-
_extractParameters(parameterValues)
-
Extract parameters from given path.
Parameters:
Name Type Description parameterValues
Array.<string> Returns:
Params object.
- Type
- Object.<string, ?string>
-
_getClearParamName(rawParam)
-
Extract clear parameter name, e.q. '?name' or 'name'
Parameters:
Name Type Description rawParam
string Returns:
- Type
- string
-
_getParameterNames(pathExpression)
-
Extracts the parameter names from the provided path expression.
Parameters:
Name Type Description pathExpression
string The path expression.
Returns:
The names of the parameters defined in the provided path expression.
- Type
- Array.<string>
-
_getParameters(path)
-
Parses the provided path and extract the in-path parameters. The method decodes the parameters and returns them in a hash object.
Parameters:
Name Type Description path
string The URL path.
Returns:
The parsed path parameters.
- Type
- Object.<string, string>
-
_getQuery(path)
-
Extracts and decodes the query parameters from the provided URL path and query.
Parameters:
Name Type Description path
string The URL path, including the optional query string (if any).
Returns:
Parsed query parameters.
- Type
- Object.<string, ?string>
-
_getSubparamPattern(delimeter)
-
Get pattern for subparameter.
Parameters:
Name Type Description delimeter
string Parameters delimeter
Returns:
- Type
- string
-
_getTrimmedPath(path)
-
Trims the trailing forward slash from the provided URL path.
Parameters:
Name Type Description path
string The path to trim.
Returns:
Trimmed path.
- Type
- string
-
_isOptionalParamInPath(path, paramName)
-
Returns true, if paramName is placed in path.
Parameters:
Name Type Description path
string paramName
string Returns:
- Type
- boolean
-
_isParamOptional(paramName)
-
Checks if parameter is optional or not.
Parameters:
Name Type Description paramName
string Returns:
return true if is optional, otherwise false
- Type
- boolean
-
_isRequiredParamInPath(path, paramName)
-
Returns true, if paramName is placed in path and it's required.
Parameters:
Name Type Description path
string paramName
string Returns:
- Type
- boolean
-
_replaceOptionalParametersInPath(path, optionalParams)
-
Convert main optional parameters to capture sequences
Parameters:
Name Type Description path
string The URL path.
optionalParams
array.<string> List of main optimal parameter expressions
Returns:
RegExp pattern.
- Type
- string
-
_replaceOptionalSubParametersInPath(path, optionalSubparamsOthers, optionalSubparamsLast)
-
Convert optional subparameters to capture sequences
Parameters:
Name Type Description path
string The URL path (route definition).
optionalSubparamsOthers
array.<string> List of all subparam. expressions but last ones
optionalSubparamsLast
array.<string> List of last subparam. expressions
Returns:
RegExp pattern.
- Type
- string
-
_replaceRequiredSubParametersInPath(path, clearedPathExpr)
-
Convert required subparameters to capture sequences
Parameters:
Name Type Description path
string The URL path (route definition).
clearedPathExpr
string The original cleared URL path.
Returns:
RegExp pattern.
- Type
- string
-
_substituteOptionalParamInPath(path, paramName, paramValue)
-
Replace optional param placeholder in path with parameter value.
Parameters:
Name Type Description path
string paramName
string paramValue
string Returns:
New path.
- Type
- string
-
_substituteRequiredParamInPath(path, paramName, paramValue)
-
Replace required parameter placeholder in path with parameter value.
Parameters:
Name Type Description path
string paramName
string paramValue
string Returns:
New path.
- Type
- string
-
extractParameters(path)
-
Extracts the parameter values from the provided path. The method extracts both the in-path parameters and parses the query, allowing the query parameters to override the in-path parameters.
The method returns an empty hash object if the path does not match this route.
Parameters:
Name Type Description path
string Returns:
Map of parameter names to parameter values.
- Type
- Object.<string, ?string>
-
getController()
-
Returns the full name of the controller to use when this route is matched by the current URL, or an Object Container-registered alias of the controller.
Returns:
The name of alias of the controller.
- Type
- string
-
getName()
-
Returns the unique identifying name of this route.
Returns:
The name of the route, identifying it.
- Type
- string
-
getOptions()
-
Return route additional options.
Returns:
- Type
- Object
-
getPathExpression()
-
Returns the path expression, which is the parametrized pattern matching the URL paths matched by this route.
Returns:
The path expression.
- Type
- string
-
getView()
-
Returns the full name of the view class or an Object Container-registered alias for the view class, representing the view to use when this route is matched by the current URL.
Returns:
The name or alias of the view class.
- Type
- string
-
matches(path)
-
Tests whether the provided URL path matches this route. The provided path may contain the query.
Parameters:
Name Type Description path
string The URL path.
Returns:
true
if the provided path matches this route.- Type
- boolean
-
toPath( [params])
-
Creates the URL and query parts of a URL by substituting the route's parameter placeholders by the provided parameter value.
The extraneous parameters that do not match any of the route's placeholders will be appended as the query string.
Parameters:
Name Type Argument Default Description params
Object.<string, (number|string)> <optional>
{} The route parameter values.
Returns:
Path and, if necessary, query parts of the URL representing this route with its parameters replaced by the provided parameter values.
- Type
- string