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.
- Host: GitHub
- URL: https://github.com/thinkphp/router.js
- Owner: thinkphp
- Created: 2012-02-21T19:44:50.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-02-23T08:17:57.000Z (almost 14 years ago)
- Last Synced: 2024-04-14T14:54:28.839Z (almost 2 years ago)
- Language: JavaScript
- Homepage: http://thinkphp.github.com/router.js/
- Size: 94.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Router
======
This plugin provides methods for routing client-side pages and connecting them to actions and events.

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