hash-router

A frontend router for the hash change event

hash-router

A frontend router for the hash change event

var HashRouter = require("hash-router")
 
var router = HashRouter()
router.addRoute("#/", renderHome)
router.addRoute("#/login", showLoginDialog)
 
router.on("hash", function (hashevent) {
  console.log("hash changed!", hash)
})
 
window.addEventListener("hashchange", router)
router() // start the router 
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
}

npm install hash-router

  • Raynos