wadim / kronis-router

Lightweight js router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kronis-router

Lightweight js router

Methods

Method Argument Description
addRoute todo todo
addRoutes todo todo
getRoutes todo todo
setNotFoundRoute todo todo
setBeforeRoute todo todo
trigger todo todo
executeMultipleRoutes todo todo

Functions on Router function

Function Arguments Description
isActiveRoute todo todo
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

About

Lightweight js router

License:MIT License


Languages

Language:JavaScript 94.3%Language:HTML 5.7%