0.2.2 • Published 8 years ago

rur v0.2.2

Weekly downloads
1
License
ISC
Repository
-
Last release
8 years ago

RUR

Minimal client-side router.

  • named routes
  • pretty urls
  • simple, easy to use & understand, framework-agnostic
  • dependency-free, ES5-compatible
  • readable source code

Install

npm install rur --save

Usage

var Router = require('rur');
var r = new Router();

r.routes = [
  {name: 'home', path: ''},
  {name: 'users', path: 'users'},
  {name: 'show-user', path, 'users/:id'},
  {name: 'edit-user', path, 'users/:id/edit'}
];

r.onChange = function(){
  if ( ! r.state){
    return r.go('home');
  }

  // current route as defined (including custom data)
  console.log(r.state.route);

  // path params (hash)
  console.log(r.state.params);
};

r.start();

To get URL

r.getUrl('edit-user', {id: 1});

To go to another page

r.go('edit-user', {id: 1});

HTML5

Currently unsupported

  • IE9 does not support pushState() at all
  • IE10/Edge support is still buggy
  • not even Firefox & Webkit currently behave the same

It is probably going to appear in future with little or no change in current API but it will take some to implement correctly

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

9 years ago

0.0.0

9 years ago