4.0.0 • Published 5 years ago

pick-path v4.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

pick-path

Build Status Greenkeeper badge

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