egoist
2/9/2017 - 12:09 PM

path-extract.js

import routage from 'routage'

const router = routage([
  {
    path: '/',
    render() {
      console.log('home')
    }
  },
  {
    path: '/about',
    render() {
      console.log('about')
    }
  },
  {
    path: '/user/:username',
    render(params) {
      console.log(`Hi ${params.username}`)
    }
  }
])

router.start()
const extract = require('path-extract')

const params = extract('/user/:username', '/user/egoist')

console.log(params)
//=>
{
  username: 'egoist'
}