Skip to content

A lightweight javascript utility for building hash routing in your front-end application.

License

Notifications You must be signed in to change notification settings

satyendra2013/hash-router-mjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A lightweight javascript utility for building hash routing in your front-end application.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published