path-dispatcher

1.1.2 • Public • Published

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

Package Sidebar

Install

npm i path-dispatcher

Weekly Downloads

7

Version

1.1.2

License

MIT

Last publish

Collaborators

  • sugarshin