pick-path
v4.0.0
Published
A simple route handling tool. Mapping a URL to a handler
Downloads
18
Maintainers
Readme
pick-path
Rather simple route picking tool
API
<Value>(path: string, routes: Routes<Value>) => Match<Value>
Example
import pickPath from 'pick-path'
import { Home, About, AboutTeam, AboutMission, Item, NotFound } from './pages'
const { pattern, value, params } = pickPath('/item/10', {
'/': Home,
'/about/': { // must have trailing `/`
// nested routes object (infinite nesting possible)
'/': About,
'/team': AboutTeam,
},
'/about/mission': AboutMission
'/item/:id': Item
// '*': NotFound // https://github.com/mightyiam/pick-path/issues/10
});
pattern // '/item/:id'
value // Item
params // ['10']
Thanks
- Eden Berger (edenberger)
- https://github.com/staltz/switch-path
- https://github.com/joakimbeng/handle-path