Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/debjitbis08/ub-router
A front-end router with path segment validation
https://github.com/debjitbis08/ub-router
Last synced: 22 days ago
JSON representation
A front-end router with path segment validation
- Host: GitHub
- URL: https://github.com/debjitbis08/ub-router
- Owner: debjitbis08
- License: gpl-3.0
- Created: 2014-11-21T09:45:14.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-26T21:08:36.000Z (over 9 years ago)
- Last Synced: 2024-12-17T11:13:17.245Z (23 days ago)
- Language: JavaScript
- Homepage:
- Size: 215 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ub-router
=========A front-end router with path segment validation.
Examples
--------###Basic Usage
```javascript
var StaticR = function () {
return function handle() {
var el = document.getElementById("content");
el.innerHTML = "Static 3";
};
};var CountR = function (n) {
var map = [ "One", "Two" ];
return function handle() {
var el = document.getElementById("content");
el.innerHTML = map[n - 1];
};
};Routes
.add("page/three", StaticR)
.add("page/#Number", CountR)
.listen();/**
* "page/1" is valid
* "page/two" is invalid
* "page/three" is valid
*/
```###Adding a custom path piece data type
To create a new PathPiece data type use the pathPiece
function. It will also be available in the Routes.types
namespace for future use.```javascript
Routes.pathPiece("Natural", function (piece) {
var n = Routes.fromPathPiece(Routes.types.Integer)(piece);
if (n === null || n < 0) { return null; } else { return n; }
}, function (n) {
return String(n);
});Routes
.add("page/#Natural", CountR)
.listen();
```