Route
A configuration object defining how a route is set up.
Definition
- Library: tramway-core-router
Create
tramway create:route ProductController getOne /products --methods get --args id --create-controller
Locations
- Implementation:
src/config/parameters/global/routes.js
- Dependency Injection:
src/config/parameters/global/routes.js
Specs
Attribute | Expected Values | Default Values | Notes |
---|---|---|---|
path | Unparameterized path string | "/" | If no path is specified, the router will default to root. |
controller | string | undefined | The key of the Controller as configured in dependency injection. |
action | string | undefined | The name of the Controller method dedicated to handling the route. If not a restful route and no action is specified, the app will break |
restful | boolean | undefined | If the controller is a restful controller - note that action attribute will be ignored |
methods | ["get", "post", "put", "delete", "all"] | ["get"] | Indicates which http methods get assigned the controller. Restful routes will ignore this setting as it is automatically bound by implenentation |
arguments | string[] | "" | An optional ordered array of arguments to add to the path. ["id", "name"] equates to "/:id/:name" |
policy | string | undefined | The key of the Policy to apply to the route. Ignored if unpresent, applies a policy or authentication strategy before allowing the router to proceed to the controller when a request is made |
Example
const routeValues = [{"controller": "controller.main","action": "index","methods": ["get"]},{"controller": "controller.product","action": "getOne","path": "products","methods": ["get"],"arguments": ["id"],"links": [{"label": "accessories", "link": "accessories"},]},{"controller": "controller.product","action": "create","path": "products","methods": ["post"]},{"controller": "controller.product","action": "update","path": "products","methods": ["patch"],"arguments": ["id"]},{"controller": "controller.product","action": "replace","path": "products","methods": ["put"],"arguments": ["id"]},{"controller": "controller.product","action": "delete","path": "products","methods": ["delete"],"arguments": ["id"]},{"controller": "controller.accessory","path": "products/:productId/accessories","restful": true,"policy": "policy.product",},];export default routeValues;