Skip to content

sugarshin/path-dispatcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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