Router
Manages routing
Table of Contents
-
Methods
- _buildRoute()
- _generateControllerHandlers(controlleraction)
- _getPathSegment(resourceaction)
- _loadControllers()
- _lookupSerializer(name)
- _mapControllerAction(resourcecontrolleractionoptions)
- _registerControllerHooks(controllerhandlers)
- _registerLegacyControllerHooks(controlleractionhandlers)
- namespace(namespaceroutes)
- resource(nameoptions)
- route(pathoptions)
- Properties
Constructor
Router
-
registry
Parameters:
-
registry
Object
Methods
Consistently builds a route from a set of path segments using Route
Returns:
route object with path property
Generates a path segment from a given resource name
Returns:
pathSegment (e.g. :userId
)
_loadControllers
()
loads controllers from the loader
Attempts to lookup a serializer by 'name' in the module loader. If one exists it is instantiated and registered by 'name'. If one does not exist the default JSONSerializer is instantiated and registered.
Parameters:
-
name
Stringlowercase singular lookup name (e.g. "user")
Returns:
serializer instance
_mapControllerAction
-
resource
-
controller
-
action
-
options
maps a resource controller action and route
_registerControllerHooks
-
controller
-
handlers
Registers controller beforeModel and afterModel hooks
Parameters:
_registerLegacyControllerHooks
-
controller
-
action
-
handlers
Registers legacy controller before/after hooks
Parameters:
namespace
-
namespace
-
routes
Bind a set of routes to a namespace. Uses _buildRoute to normalize the path
Parameters:
-
namespace
Stringthe namespace to bind to, with or without leading slash
-
routes
Object[][]array of routes to bind to the namespace
Example:
Router.map(function () {
this.namespace("/users/:userId", [
{ path: "/setProfileImage", using: "user:setImage", method: "post" }
])
});
resource
-
name
-
options
Register a resource and wire up restful endpoints. Uses _buildRoute to normalize the path and builds your 5 basic CRUD endpoints
Parameters:
Example:
Router.map(function () {
this.resource("user");
// Optionally prefix this resource with a namespace
this.resource("user", { namespace: "api" })
});
route
-
path
-
options
Register a single route. Uses _buildRoute to normalize the path
Parameters:
Example:
Router.map(function () {
this.route("/user/foo", { using: "users:foo", method: "get" });
});