sym-router

0.0.5 • Public • Published

sym-router

sym-router is a lightweight, client-side routing library that allows you to create "single page" applications using Hashes or HTML5 pushState. It was originally forked from PathJS but has been completely rewritten.

npm install sym-router

Features

  • Lightweight
  • Supports the HTML5 History API, the 'onhashchange' method, and graceful degredation
  • Supports root routes, rescue methods, paramaterized routes, optional route components (dynamic routes)
  • Well Tested (tests available in the ./tests directory)
  • Compatible with all major browsers (Tested on Firefox 25, Chrome 31, IE8, IE10)
  • Independant of all third party libraries, but plays nice with all of them

Using sym-router - A Brief Example

var router = require('sym-router');

function clearPanel() {
    // You can put some code in here to do fancy DOM transitions,
    // such as fade-out or slide-in.
}

router.map("/users").to(function() {
    alert("Users!");
});

router.map("/comments").to(function() {
    alert("Comments!");
}).exit(clearPanel);

router.map("/post/:id").to(function(params) {
    alert("Post " + params.id + "!");
}).exit(clearPanel);

// if there is no matching route
router.rescue(function(path) {
    alert("No route round for " + path);
});

router.listen();

Running Tests

Make sure all dependencies are installed first:

npm install

To run the tests, use npm test to test the routing and routes. For the actual browser history tests, build the JS files with: make and run python -m SimpleHTTPServer. Open the html files in http://10.0.2.2:8000/tests/browser. Everything should go to green eventually.

If you're on Windows, just run the commands in the Makefile manually.

Readme

Keywords

none

Package Sidebar

Install

npm i sym-router

Weekly Downloads

1

Version

0.0.5

License

MIT

Last publish

Collaborators

  • arian