@tofandel/hash-router
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

@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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.4
    1
    • latest

Version History

Package Sidebar

Install

npm i @tofandel/hash-router

Weekly Downloads

1

Version

0.1.4

License

GPL-3.0-or-later

Unpacked Size

8.76 kB

Total Files

5

Last publish

Collaborators

  • tofandel