Giter Club home page Giter Club logo

sym-router's Introduction

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.

sym-router's People

Contributors

mtrpcic avatar arian avatar rmontgomery429 avatar jmisavage avatar

Stargazers

Nikos M. avatar Mike Gioia avatar Johannes Konst avatar Garrick Cheung avatar Coen Baars avatar

Watchers

 avatar Michael Russell avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.