path-dispatcher
v1.1.2
Published
Static url dispatcher
Downloads
10
Maintainers
Readme
path-dispatcher
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
- Fork it!
- Create your feature branch: git checkout -b my-new-feature
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request :D
License
© sugarshin