pick-path

A simple route handling tool. Mapping a URL to a handler


Keywords
routing, route, url, path, match, switch, map
License
MIT
Install
npm install pick-path@4.0.0

Documentation

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