track-router

0.0.9 • Public • Published

TrackRouter

Router for track.

Build Status

Installation

npm

npm install track-router

Usage

const TrackRouter = require('track-router');
 
TrackRouter.configure(() => {
  get('/', {to: require('homes/index'), as: 'root'}); // `/`
 
  namespace('hoges', () => {
    get('/',   {to: 'hoges/index', as: 'index'}); // `/hoges`
    get(':id', {to: 'hoges/show',  as: 'show'});  // `/hoges/:id`
 
    namespace('fugas', () => {
      get(':id', {to: 'hoges/fugas/show',  as: 'show'}); // `/hoges/fugas/:id`
    });
  });
 
  namespace('foo', () => {
    namespace(':id', () => {
      get('/bar', {to: 'foo/bar/index', as: 'bar'}); // `/foo/:id/bar`
    });
  });
 
  get('/numbers/:num', {to: 'numbers/show', as: 'numbers', constraints: {num: /^\d+$/}})
});
 
TrackRouter.getPath('root');                 // `/`
TrackRouter.getPath('hoges_show', {id: 777}) // `/hoges/777`
TrackRouter.getPath('foo_bar',    {id: 888}) // `/foo/888/bar`

Readme

Keywords

none

Package Sidebar

Install

npm i track-router

Weekly Downloads

1

Version

0.0.9

License

ISC

Unpacked Size

14.3 kB

Total Files

20

Last publish

Collaborators

  • alfa-jpn