A frontend router for the hash change event
JavaScript
Latest commit ad611ee May 3, 2014 @Raynos 0.4.0
Permalink
Failed to load latest commit information.
test fix bugs May 3, 2014
.gitignore initial Jun 17, 2013
.travis.yml initial Jun 17, 2013
LICENCE initial Jun 17, 2013
README.md updated example Jul 9, 2013
index.js fix bugs May 3, 2014
package.json 0.4.0 May 3, 2014

README.md

hash-router

A frontend router for the hash change event

Example

var HashRouter = require("hash-router")

var router = HashRouter()
router.addRoute("#/", renderHome)
router.addRoute("#/login", showLoginDialog)

router.on("hash", function (hash, event) {
  console.log("hash changed!", hash)
})

window.addEventListener("hashchange", router)
router() // start the router

Docs

type RouteHandler := (hash: String, opts: {
    params: Object,
    splats: Array<String>,
    newUrl: String,
    oldUrl: String
}) => void

hash-router := (opts?: {
    setRoute?: (String) => void,
    getRoute?: () => String
}) => EventEmitter & {
    (HashChangeEvent?) => void,
    go: (String) => void,
    get: () => String,
    addRoute: (pattern: String | RegExp, handler: RouteHandler) => void
}

Installation

npm install hash-router

Contributors

  • Raynos

MIT Licenced