route-mapper
Generate Rails Style Routing & RESTful Routes. See Rails Routing doc.
Write with ES6+
, build with Babel for ES5
.
Usage
let routeMapper = ;routeMapper // You can have the root of your site routed with "root" // /products/233 controller = catalog, action = view // Example named route that can be invoked with purchase_path(id: product.id) // /products/233/purchase === purchasePath(233) // Example resource route (maps HTTP verbs to controller actions automatically): // Example resource route with options: // Example resource route with sub-resources: // Example resource route with more complex sub-resources: // Example resource route with concerns: // Example resource route within a namespace: ; });
Features
- Nesting
- Namespace
- Resources
- RESTful
- Chaining
- Named Routes
- URL Helpers
- Pluralized or Singularized
- CamelCase or Underscore Styles
- ...
APIs
get()
,post()
,put()
,delete()
..., HTTP verbsroot
match
scope
controller
namespace
constraints
resource
resources
collection
member
nested
concern
concerns
draw(filename)
Examples
Express example
'use strict' const app = let routeMapper = routeMapper app routeMapperroutes appconsole
Koa example
'use strict' const app = const router = const routeMapper = routeMapper scope path: '~:username?' module: 'users' as: 'user' { routeMapper } routeMapperroutes app consoleapp