Skip to content

rerthal/router.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 

Repository files navigation

Router.js

This project uses the Class.js project

Router Object

The router controls all system routes to structure the program execution

Track

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');
    });
});

Context Object

The context object is where the callbacks are executed.

Mask

Usage example:

var router = new Router(function () {
    this.track('/animal/:id', function () {
        console.log(this.mask()); // => /animal/:id
    });
});

Url

Usage example:

var router = new Router(function () {
    this.track('/animal/:id', function () {
        console.log(this.url()); // => /animal/dog
    });
});

Extend

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
    });
});

Bitdeli Badge

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •