@tofandel/hash-router

v0.1.3
A frontend router for the hash change event
hash router

@tofandel/hash-router

Build coverage npm version dependencies

A frontend router for the hash change event

Example

import HashRouter from "@tofandel/hash-router";

const router = new HashRouter({
  '/': renderHome,
  '/login': showLoginDialog,
  '*': fallbackRoute
})
router.addRoute('/another', anotherRouteCb);

router.on("routed", function (hash, event) {
  console.log("Route has changed!", hash, event)
})
router.on("not-found", function (hash, event) {
  console.log("Didn't find a route", hash, event) // This won't ever fire if the '*' route is set
})

router.started.then(() => {
  console.log('Router is ready');
  router.go('/login');
})

Installation

npm install @tofandel/hash-router

npm i @tofandel/[email protected]

Metadata

Downloads

Maintainers