Routes
Routes are defined in config/routes.js. Any page in app/views/pages is also rendered when no route matches first.
A route is a key (a path, or an HTTP verb and a path) pointing to controller#action, or to an object with a controller and options.
module.exports = { '/test': 'user#info', // defaults to 'get /test'
'/abc/:id': 'moo#iii', // the controller does not exist: the route is not loaded
'/user/find': 'user#fetch',
'get /poo': 'user#postinfo',
'post /poo': 'user#create',
'get /secured': { controller: 'secureController#index', roles: ['admin'], },
'resources todo': { controller: 'todo', },
'crud categories': { scope: 'api', controller: 'categories', omit: ['destroy'], // the DELETE route is not created },};In development, routes pointing to a missing controller answer 501 Not Implemented so you notice; in production they are skipped. GET /_routes and GET /_controllers list what is loaded, and pressing R or U in the terminal prints the same.
Give a route an array of roles and only authenticated users whose roles contain every one of them can reach it. Everybody else is redirected to /login.
The crud keyword replaces the HTTP verb and creates the API routes for a resource:
// 'crud happy': 'life'
GET /happy => life#indexPOST /happy => life#createPATCH /happy/:id => life#updatePUT /happy/:id => life#updateDELETE /happy/:id => life#destroyResources
Section titled “Resources”The resources keyword adds the view routes to CRUD:
// 'resources happy': 'life'
GET /happy => life#indexPOST /happy => life#createPATCH /happy/:id => life#updatePUT /happy/:id => life#updateDELETE /happy/:id => life#destroy
GET /happy/:id/edit => life#editGET /happy/new => life#newGET /happy/:id => life#showAdd scope to prefix the generated routes: scope: 'api' turns /happy into /api/happy.
Omit (crud and resources only)
Section titled “Omit (crud and resources only)”Add an omit array to skip some of the generated actions: omit: ['destroy', 'edit'].
Named paths
Section titled “Named paths”Every loaded route gets a name, <action>_<controller>_path (show_todo_path, index_categories_path), that the views receive in paths filtered by the current user’s roles. The React helpers pathFor() and getRoute() build URLs from these names, so a renamed route does not break your links.
