A simple client-side router with support for old browsers (Inspired on AngularJS Router and Laravel Router).
Note: The router use hash.
-
Using bower:
$ bower install motion-router
-
Using npm:
$ npm install motion-router
// New router instance
var router = new MotionRouter();
// Routes
router
.when('/', function() {
console.log('Home');
})
.when('/one', callback);
// Prefix for routes
router.prefix('/group')
.when('/one', callback) // #/group/one
.when('/two', callback); // #/group/two
// Not registered route
router
.otherwise(function() {
router.redirect('/'); // Redirection to home
});
// Run =D
router.run();
$ npm run example