kieran / barista

A URL router / generator for NodeJS
https://kieran.github.io/barista/
MIT License
111 stars 22 forks source link

Adding an additional information to route #26

Closed misterjt closed 10 years ago

misterjt commented 10 years ago

I need to store the information about what view to use in the routes. And every day without this feature in the Barista Router one kitten is crying.

kieran commented 10 years ago

You can attach arbitrary default params to a route:

// define the route                       with default params
router.get('/posts/:id').to('posts.show', {lang:'en'} )

// resolve it later
router.first('/posts/5','GET')
//=> { controller: 'posts', action: 'show', id: 5, lang:'en' }

The original use case was defining defaults for route segments:

router.get('/posts/:id(.:format)').to('posts.show', {format:'pdf'} )

router.first('/posts/5','GET')
//=> { controller: 'posts', action: 'show', id: 5, format:'pdf' }

router.first('/posts/5.html','GET')
//=> { controller: 'posts', action: 'show', id: 5, format:'html' }

but you could use it for whatever you want I guess...

Although I have no idea what you're doing specifically, specifying a view in the route seems like The Wrong Thing To Do™