1.0.2 • Published 4 years ago

hash-router-mjs v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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.