new tart.mvc.uri.Router(basePath, defaultRoute, renderer, redirectionType)
Router class that is responsible for routing the incoming request to appropriate controller and actions with appropriate parameters. The application routes are added to the Router instance and every time the URI changes, it routes the request to the appropriate controller/action.
Name | Type | Description |
---|---|---|
basePath |
string |
The URI to parse. |
defaultRoute |
tart.mvc.uri.Route |
Default URI route that is used as fallback when no appropriate controller/action is found. |
renderer |
tart.mvc.Renderer |
Renderer instance to actually execute the routing and draw the layout and view. |
redirectionType |
tart.mvc.uri.Router.RedirectionType |
optional
How the redirection will affect the url. By default, all redirections change the url. |
Members
-
statictart.mvc.uri.Router.RedirectionType
-
Constant values for redirection types. CLASSICAL makes all redirections with the url changing and reflecting the new path. SILENT_ALL makes all redirections without the url changing. SILENT_ONLY_DEFAULT makes only the error redirections silent. All the other ones are CLASSICAL.
Properties:
Name Type Default Description CLASSICAL
0 SILENT_ALL
1 SILENT_ONLY_DEFAULT
2 SILENT
3
Methods
-
addRoute(route)
-
Adds a route to the router.
Name Type Description route
tart.mvc.uri.Route Route to be added.
-
getAction(){function}
-
Returns the active action.
Returns:
Type Description function Active action. -
getBasePath(){string}
-
Return uri base path
Returns:
Type Description string uri base path. -
getController(){function}
-
Returns the active controller.
Returns:
Type Description function Active controller. -
getCurrentRoute(){tart.mvc.uri.Route}
-
Returns:
Type Description tart.mvc.uri.Route the active URI route. -
getCustomQuery(){string}
-
Returns custom query parameter.
Returns:
Type Description string customQuery Retrieved key and parameter pair from uri. -
getDefaultRoute(){tart.mvc.uri.Route}
-
Returns the default route associated with this router.
Returns:
Type Description tart.mvc.uri.Route Default route. -
getParams(){Object}
-
Returns:
Type Description Object The active parameters. -
getRoute(name){tart.mvc.uri.Route}
-
Returns a route with a given name. If no matching route is found, this method throws a tart.Err.
Name Type Description name
string Route name to look up.
Returns:
Type Description tart.mvc.uri.Route Route with the given name. Note that this function never returns null; this is a Google Closure Compiler fix. -
getRoutes(){Array.<tart.mvc.uri.Route>}
-
Returns:
Type Description Array.<tart.mvc.uri.Route> The array of routes in this router. -
redirectToAction(controller, action, params, redirectionType){tart.mvc.uri.Redirection}
-
Redirects to a given controller and action with given parameters. This method is a convenience method for redirectToRoute in that one may use without hard-coding the name of the route. Keep in mind that there still needs to be an actual route that will resolve to the given controller and action.
Name Type Description controller
tart.mvc.ControllerTemplate The controller child class that the redirection will resolve to.
action
tart.mvc.ActionTemplate The action that the redirection will reeolve to.
params
Object.<string, *> optional The object that contains parameters to be sent to the route. Make sure that the parameters fully match the route's requirements, otherwise a tart.Err may be thrown.
redirectionType
tart.mvc.uri.Router.RedirectionType optional How the redirection will affect the url.
Returns:
Type Description tart.mvc.uri.Redirection Explicitly make known that this is a redirection, so that the redirector stops execution after this action. -
redirectToRoute(route, params, redirectionType){tart.mvc.uri.Redirection}
-
Redirects to a given route with given parameters.
Name Type Description route
tart.mvc.uri.Route | string The name of the route the redirection will be made to. This method will first search for the given route and may throw a tart.Err if the requested route is undefined.
params
Object.<string, *> optional The object that contains parameters to be sent to the route. Make sure that the parameters fully match the route's requirements, otherwise a tart.Err may be thrown.
redirectionType
tart.mvc.uri.Router.RedirectionType optional How the redirection will affect the url.
Returns:
Type Description tart.mvc.uri.Redirection Explicitly make known that this is a redirection, so that the redirector stops execution after this action. -
route(uri)
-
Responsible for routing the incoming request to appropriate controller and actions with appropriate parameters. The application routes are added to the uri.Router instance.
Name Type Description uri
string optional The URI to parse.
-
setBasePath(path)
-
Set base path
Name Type Description path
string uri base path.