2way-router
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -90,2 +90,3 @@ var RegExpParam = require('./param/RegExpParam'); | ||
var usedParams = {}; | ||
params = params || {}; | ||
@@ -92,0 +93,0 @@ function createUrl() { |
{ | ||
"name": "2way-router", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "2-way router", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -83,3 +83,3 @@ 2way-router | ||
function pageController(req, res, params) { | ||
var pageContent = 'page: ' + name + ', params: <pre>' + JSON.stringify(params, null, ' ') + '</pre>'; | ||
var pageContent = 'page: ' + name + ', params: <pre>' + JSON.stringify(params.merge(), null, ' ') + '</pre>'; | ||
vow.all(links.map(function (link) { | ||
@@ -109,3 +109,3 @@ return router.url(link.page, link.params || {}); | ||
app.use(function (req, res) { | ||
router.findRoute(req.path).then(function (info) { | ||
router.findRoute(req.url).then(function (info) { | ||
info.route.controller()(req, res, info.params); | ||
@@ -118,1 +118,31 @@ }, function () { | ||
``` | ||
#### API | ||
##### Router | ||
```router.route(pathTemplate)``` - creates new ```Route``` | ||
```router.findRoute(url, [options])``` - searchs for matching route, returns ```Promise<Route>``` | ||
```router.url(routeName, [params])``` - creates url for route with name *routeName*, returns ```Promise<string>``` | ||
```router.registerType(typeConstructor, names)``` - registers new param type for further usage in routes, must be called before any ```router.route``` calls, type example can be found at [NumberParam.js] | ||
[NumberParam.js]: lib/param/NumberParam.js | ||
##### Route | ||
```route.name([newName])``` - get/set route name | ||
```route.controller([newController])``` - get/set route controller | ||
```route.url([params])``` - creates url for this route, returns ```Promise<string>``` | ||
##### RouteParams | ||
```params.getRouteParam(name, [defaultValue=null])``` - get route param value (for example ```id``` in route ```"/news/{id:int}/"```) | ||
```params.getQueryParam(name, [defaultValue=null])``` - get query string param with given *name* (last one if many are present), returns ```string``` | ||
```params.getQueryParamValues(name)``` - get all values for query string param with given *name*, returns ```string[]``` | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38591
988
146