• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    JavaScript
  • Created about 12 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Jquery plugin to handle routes for both hash and push state.

jquery router plugin

This plugin handles routes for both hash and push state.

Why? Why another routing plugin? Because i couldn't find one that handles both hash and pushstate.

How to add routes

To add route you simply call the add function, providing it with the actual route string, an optional id, and the callback.

$.router.add(route, [id], callback);

Example:

// Adds a route for /items/:item and calls the callback when matched
$.router.add('/items/:item', function(data) {
	console.log(data.item);
});

or

// Adds a route for /items/:item and calls the callback when matched, but also has
// a reference to the routes id in $.router.currentId
$.router.add('/items/:item', 'foo', function(data) {
	console.log(data.item);
});

How to change urls and trigger routes

You can also change the current url to a route, and thereby triggering the route by calling go.

$.router.go(url, title);

Example:

// This will change the url to http://www.foo.com/items/mycoolitem and set the title to
// "My cool item" without reloading the page. If using hashes instead, it will use the url
// http://www.foo.com/#!items/mycoolitem.
// If a route has been set that matches it, it will be triggered.
$.router.go('/items/mycoolitem', 'My cool item');

Reseting all routes

If you need to remove all routes (which is good when testing) you just call:

$.router.reset();

Dealing with 404's

If a url is entered which doesn't fire a route callback (a.k.a. 404 Not Found) you can add your error callback to take that case and make it beautiful.

$.router.addErrorHandler(function (url) {
	// url is the URL which the router couldn't find a callback for
	console.log(url);
});

License

(The MIT License)

Copyright (c) 2011 Camilo Tapia <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

webhook-deployer

Deployer server app triggered by (github) webhooks
JavaScript
69
star
2

node-nfc

A first try at binding libnfc to node. This project is right now not good enough to use.
C++
68
star
3

ryb-color-mixer

Mix colors as expected in real life (subtractive) in javascript.
JavaScript
32
star
4

plugwisejs

Plugwise API for nodejs
JavaScript
17
star
5

heos

A nodejs module to communicate with your Denon Heos speakers
JavaScript
16
star
6

passport-http-2legged-oauth

Oauth 2-legged strategy for passport
JavaScript
12
star
7

examples

Examples
PHP
12
star
8

frnt

Front-end server for your website.
JavaScript
11
star
9

nunt

Superlightweight event system for javascript. Easy to use just in the client, easy to use on the server and seamless communication between both. If you like to create event based apps, this is for you.
JavaScript
8
star
10

routes-for-wp

A plugin to handle routes in wordpress
PHP
6
star
11

zonar

Network service discovery tool for nodejs. Makes discovering things a breeze.
JavaScript
4
star
12

talk

Talk is a npm module to abstract the communication between your apis or micro-services
JavaScript
4
star
13

screenshooter

Command lien tool i node to take full-length screenshots of websites
JavaScript
4
star
14

fakes

Create super simple fake api with relevant data (and in the future you will be able to test the schema against your real endpoints)
JavaScript
4
star
15

docker-node-dev-environment

Docker node.js Development Environment for the TMUX + (neo)VIM user in you
Vim Script
3
star
16

jetro

A grid system, like metro, with js, and no dependencies
3
star
17

_bmvc

A small, yet powerfull and flexible mvc for javascript
JavaScript
2
star
18

progressive-loadable

Progressively load and hydrate components when they are in the viewport.
JavaScript
2
star
19

facebook-testers-tool

A simple nodejs module to create and connect facebook testers trough their api
2
star
20

wp-fortune-cookie

Creates a (fortune) cookie every 24 hours when the user visits your site.
PHP
1
star
21

webdriverjs-selenium-bundle

Want to use webdriverjs without needing to start the selenium-server separately? In that case, this is a bundle for you!
JavaScript
1
star
22

optimicss

CSS optimization helper for critical paths.
JavaScript
1
star
23

.vim

my vim
Vim Script
1
star
24

super-api-cache

JavaScript
1
star
25

camme.github.com

Site
JavaScript
1
star
26

.janus

my vim plugins
Vim Script
1
star
27

autonodos

A nodejs home automation server for plugwise. Control your world from your phone, browser or just by itself
JavaScript
1
star
28

nginx-letsencrypt

Shell
1
star