0.1.1 • Published 8 years ago

roun v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Roun

Build Status

A hash base route library ( < 3KB )

Example

On browser

<script src="roun.js"></script>
<script>
  var route = roun({
    notFoundPath: '/404',
    hashBase: '#!',
  });
  route.on('/', function () {
    console.log('/#!/');
  });
  route.on('/foo/:id/bar/:name', function (data) {
    console.info('id is %s, name is %s', data.id, data.name)
    console.log('/#!/foo/123/bar/john');
  });
  route.on('/foo/bar/:id', function (data) {
    console.info('id is %s', data.id)
    console.log('/#!/foo/bar/789');
  });
  route.on('/404', function () {
    console.log('/#!/404');
  });
  route.exec();
  //
  // or
  //
  // route
  //   .on('/', function () {...})
  //   .on('/foo/:id/bar/:name', function (data) {...})
  //   .on('/foo/bar/:id', function (data) {...})
  //   .on('/404', function () {...})
  //   .exec();
</script>

With browserify

const roun = require('roun');
roun().on('/', () => {});
browserify xxx.js -o bundle.js

With webpack

const roun = require('roun');
roun().on('/', () => {});
webpack xxx.js bundle.js

With rollup

import roun from 'roun/es/roun';
roun().on('/', () => {});
rollup xxxx.js -o bundle.js -f umd -n xxx

Options

namedescriptionexampledefault
notFoundPathRedirect path, when undefined path/404'/404'
hashBaseHash type# and #! and the like#

Change log