0.1.2 • Published 9 years ago

hirouter v0.1.2

Weekly downloads
10
License
-
Repository
github
Last release
9 years ago

HiRouter

HTML5 history and router, simple, powerful and no framework.

NPM version Build Status

It is a implementation of route-trie

Demo

var HiRouter = require('hirouter');
var router = new HiRouter();

// define router handler:
router
  .when('/projects/:id', function(state) {
    // body...
    console.log(state)
    // {
    //   fragment: '/projects/xxxxxxxId?debug=true',
    //   pathName: '/projects/xxxxxxxId',
    //   search: '?debug=true',
    //   params: {
    //     id: 'xxxxxxxId'
    //   }
    // }
  })
  .when('/organizations/:id', function(state) {
    // body...
    console.log(state)
  })
  .otherwise(function(state) {
    // body...
  })
// start listen
router.start();

// navigate to a url
router.navigate('/organizations/xxxId')

// navigate to a url and don't trigger route handler
router.navigate('/organizations/xxxId', {trigger: false})

API

new HiRouter(rootPath, options)

HiRouter.prototype.when(pattern, handler)

HiRouter.prototype.otherwise(handler)

HiRouter.prototype.navigate(fragment, options)

HiRouter.prototype.start(options)

HiRouter.prototype.route(fragment)

HiRouter.prototype.parsePath(fragment)

Object: HiRouter.prototype.history

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago