An open API service indexing awesome lists of open source software.

https://github.com/thinkphp/router.js

This plugin MooTools is used for routing your application URL using hashchange event.
https://github.com/thinkphp/router.js

Last synced: 3 months ago
JSON representation

This plugin MooTools is used for routing your application URL using hashchange event.

Awesome Lists containing this project

README

          

Router
======

This plugin provides methods for routing client-side pages and connecting them to actions and events.

![Screenshot](http://farm8.staticflickr.com/7179/6775343118_4a43f51b49.jpg)

How to use
----------
First at all, you must create a set of rules that represents the patterns for url matching.

Get started by creating a set of rules:

var rules = [
["/:user/forge/:action/",
function(data) {
console.log("My Profile",data.user);
}],
["/forge/:action/",
function(data) {
console.log("Add a new plugin",data.action);
}],
["/:user/settings/:action/",
function(data) {
console.loglog("Edit your profile",data.user);
}],
["/logout/",
function(data) {
console.log("Logout",data);
}]
];

`:key` acts as placeholders resulting in matching properties on the data object.

Create, simply, a new object `Router`.

var router = new Router(rules);

Be sure to call the method "match". This method iterates over the stored rules
and if a match is found, the corresponding handler is fired with a single argument, an object containing
properties matching the variable placeholders in the matching rule, otherwise returns undefined.

window.onhashchange = function() {
router.match(location.hash);
}