Skip to content

sasa-b/tiny

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

Tiny

A small hash and history api router suitable for hybrid web apps which use both the SPA and traditional approach at the same time.

API / USAGE EXAMPLES

var router = new Router();

or

var router = new Router({hybrid:true});

In the second example the router will only work for links with push-state class.

<a href="/awesome" class="push-state" data-push-state='{"title":"Awesome","foo":"bar"}'>Click me</a>

Adding routes

router.addHash('#foo', function() {
    //Do something
});

router.addRoute('/foo', function() {
  //Do something
});

Adding routes with variables

router.addHash('#foo/{bar}', function(bar) {
    //Do something
});

router.addRoute('/foo/{bar}', function(bar) {
  //Do something
});

Turning the listeners (router) on

router.listen();

Set a default action for empty hash

router.defaultHashAction = function() {
    //Do something
};

Getters

router.getRoutes();

router.getRoute(0);
router.getRoute('/foo');

router.getRouteAction(router.getRoute(0));

About

A small hash and history api router

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published