hash-router-mjs

1.0.2 • Public • Published

hash-router-mjs

A lightweight javascript utility for building hash routing in your front-end application.The first hash routing library written by following .mjs extention. Looking forward for more contributions in improving this library.

Installation

npm install hash-router-mjs

Example

import hashRouterJs from 'hash-router-mjs';

const router = hashRouterJs();
router.addRoute('#/', renderHomePage);
router.addRoute('#/signup', openSignupDialog);

router.on('hash', function (hash, e) {
  console.log('hash changed!', hash);
});

window.addEventListener('hashchange', router);
router(); // call to start the router

Documentation

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

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

Tests

We are using [tape] for the testing this utility library. To run tests, run:

npm run test

For convenience, during development you can use:

npm run watch

and watch the test be re-run at every save.

Author

  • Satyendra Pandit

Contributors

  • Satyendra Pandit

MIT Licenced

This project is licensed under the terms of the MIT license.

Package Sidebar

Install

npm i hash-router-mjs

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

8.75 kB

Total Files

7

Last publish

Collaborators

  • satyendra10