45
GitHub - kevindurb/router: A simple js router designed to solve one problem outs...
source link: https://github.com/kevindurb/router
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
router
A simple js router designed to solve one problem outside of any other frameworks like React, Angular, or Vue
Installing
npm install --save @kevindurb/router
Usage
import { router } from '@kevindurb/router'; const app = router(); app.add('/people', () => { console.log('showing people!'); }); app.add('/people/:id', ({ id }) => { console.log('load person with id: ', id); }); app.exec('/people/256'); // load person with id: 256 app.exec('/people'); // showing people!
Usage with history package
npm install --save history
import createHistory from 'history/createBrowserHistory'; import { router, mountHistory } from '@kevindurb/router'; const history = createHistory(); const app = router(); app.add('/people', () => { console.log('showing people!'); }); app.add('/people/:id', ({ id }) => { console.log('load person with id: ', id); }); history.listen(mountHistory(app)); history.push('/people/65'); // load person with id: 65
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK