Pathrouter JS
Simple routing library using HTML5 history.pushState or hashbang for web browsers.
Installation
$ npm install pathrouter
Standalone
Also, you can use the standalone version without components.
How-to
First, initialize the router:
var path = ;
Now, define some listener for any paths:
{ console;} { console; console;}
Then, add some path to the router:
;;
You can also add to an object of path-listener:
;
;
;
Somewhere in your HTML code, you should have anchor tags with #hash or #!/hash hyperlinks related to router js structure.
User
API
path(path, listener)
Creates a new path
and stores its listener
into the collection.
path
- The path you want to create.listener
- Listener you want to add to given path.
;
path#remove(path, listener)
Removes a path
or its litener
from the collection with the given path
. The listener
is optional.
path
- The path you want to remove.listener
[optional] - Listener you want to remove from given path.
path;
path#getListeners(path)
Returns a collections of listeners
with the given path
. The path
is optional. If not have a path
as parameter it returns an entire collection of path-listeners.
path
[optional]
path; // returns [user]
Contact
- Guillermo Paz (Frontend developer - JavaScript developer | Web standards lover)
- E-mail: guille87paz@gmail.com
- Twitter: @pazguille
- Web: http://pazguille.me
License
Copyright (c) 2013 @pazguille Licensed under the MIT license.