track-router
v0.0.9
Published
Router for track.
Downloads
7
Readme
TrackRouter
Router for track.
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`