This project uses the Class.js project
The router controls all system routes to structure the program execution
The method associates a route to a callback when the url is compatible with the rule of the route, the callback is executed. Remember that if an anchor call one of the routes of the router, the page is not reloaded, just executed the callback
Usage example:
var router = new Router(function () {
this.track('/animals', function () {
console.log('animals route');
});
});
The context object is where the callbacks are executed.
Usage example:
var router = new Router(function () {
this.track('/animal/:id', function () {
console.log(this.mask()); // => /animal/:id
});
});
Usage example:
var router = new Router(function () {
this.track('/animal/:id', function () {
console.log(this.url()); // => /animal/dog
});
});
Serves to generate plugins for the router, it extends new functionalities for context
Usage example:
Router.Context.extend({
alert : function (message) {
alert(message);
}
});
var router = new Router(function () {
this.track('/animal/:id', function () {
this.alert('Hi') // => Hi
});
});