1.1.6 • Published 7 years ago

kronis-router v1.1.6

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

Kronis-router

Lightweight js router

Methods

MethodArgumentDescription
addRoutetodotodo
addRoutestodotodo
getRoutestodotodo
setNotFoundRoutetodotodo
setBeforeRoutetodotodo
triggertodotodo
executeMultipleRoutestodotodo

Functions on Router function

FunctionArgumentsDescription
isActiveRoutetodotodo
Examples
var mailFunction = function() {
    console.log('Mail page')
};
var contactsFunction = function(hash, department, id) {
    /* Get some data... */
    if (this.isActiveRoute()) {
        // Do something
    }
};
var beforeFunction = function() {
    return true;
};
var router = new Router();
router.addRoute('mail', mailFunction);
router.addRoute(/^contacts\/((?:hr|dev))\/(\d+)/, contactsFunction);
router.setBeforeRoute(beforeFunction);
router.executeMultipleRoutes(true);
router.start();
Example - BeforePromiseRoute
var beforePromiseFunction = function() {
    return new Promise(function(resolve, reject) {
		someAjaxCall()
			.then(result => {
				if (result.shouldBeTrue) {
					resolve();
				}
				reject();
			})
			.catch(() => {
				reject();
			});
    });
};

var router = new Router();
router.setBeforePromiseRoute(beforePromiseFunction);
router.start();

Tests

Run tests with BusterJs

buster-server -c
buster-test
1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago