• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    JavaScript
  • Created over 12 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Javascript Router based on History.js

Build Status

slim-router: easy routing for your ajax Web applications

slim-router is a simple router for your ajax web apps. It's build upon History.js which means that RouterJs supports the HTML5 History Api with a fragment fallback for HTML4 browsers. Highly inspired by the Backbone Router it also supports passing parameters with :param and splat parts with *splat

#Usage

//Instanciate the router
var router = new Router();

//Define some routes with their respective callback function
router.route('/posts/:id', function(id){ console.log(id)});
router.route('/route/*path', function(path){ console.log(path)});
router.route('', function(){ console.log("default route")});


// Start the router
router.start();
	
/* 
* Navigate to route
* the navigate method takes two extra arguments trigger and replace
* trigger is by default true and replace is by default false
*/

router.navigate('/posts/22');
router.navigate('/posts/23', false); //ommit calling the callback
router.navigate('/route/to/heaven', true, false); //just replace without history traceback

//Navigate throught the History
router.go(2); //forward navigation
router.go(-3); //backward navigation