path-dispatcher

Static url dispatcher

Usage no npm install needed!

<script type="module">
  import pathDispatcher from 'https://cdn.skypack.dev/path-dispatcher';
</script>

README

path-dispatcher

Build Status Dependency Status Devdependency Status GitHub version License

Static url dispatcher

npm i path-dispatcher

Usage

import pathDispatcher from 'path-dispatcher';

const dispatcher = pathDispatcher({
  '/': () => {},
  '/page': [() => {}, otherFunc],
  ['/other.html']() {}
}, { rootPath: '/root/path' });

dispatcher.route('/page.html', pageFunc);

dispatcher.dispatch();

API

create dispatcher

pathDispatcher(routes = {}, config = { rootPath: '' })

route

dispatcher.route(pathName, funcOrFuncs)
@param {String}
@param {Function|Function[]} funcOrFuncs

dispatch

dispatcher.dispatch(currentPathName)
@param {String} [currentPathName = location.pathname || '']

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT

© sugarshin