kieran / barista

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

Allow extra_params to be passed to .resource() #31

Closed imperez closed 4 years ago

imperez commented 10 years ago

I noticed .to() can take a second paramter extra_params. It would be good if this was also available for .resource that would eventually get passed to their sub .to() calls.

kieran commented 10 years ago

Yeah, that's absolutely a great idea.

The loose plan in my head is to replace the default params argument in .to with it's own .defaults method, which assigns default values to routes and resources alike. Will probably release that in an upcoming point release.

In the meantime, you can achieve a similar effect by doing something like this:

// capture a reference to the resource
var rs = router.resource('Posts')

// then access the member and collection routes directly to override their options:

//                   same endpoint       new defaults
rs.member_route.to( 'Posts.show',        { lang: 'en' } )

//                     same endpoint       new defaults
rs.collection_route.to( 'Posts.index',    { something: 'else' } )

Not great, but should at least un-stick you for now!

imperez commented 10 years ago

Your workaround works great for me! It'll due until this feature is released.

Thanks!