Specifying optional arguments in routes file

24 views
Skip to first unread message

Bharath MG

unread,
May 24, 2014, 5:09:12 PM5/24/14
to action...@googlegroups.com
Hi!

How can I specify the optional arguments (inputs) in routes file? For ex, if I have posts action and which accepts 'date' as optional argument,

then in routes what I should add in this line,
   get : [ { path: '/posts', action: 'postsList' } ]

Thanks!

Evan Tahler

unread,
May 25, 2014, 11:09:10 AM5/25/14
to Bharath MG, action...@googlegroups.com
To match a route, all parts of the request must match.  So if you want an optional param, you'll need to define the route twice, IE:

get: [
  { path: '/posts',         action: 'postsList' }
  { path: '/posts/:date', action: 'postsList' }
]

You can also mix URL variables with routes, so "/posts?date=123" is also a valid match for the first route


--
 Evan Tahler
 412.897.6361
 evant...@gmail.com



--
You received this message because you are subscribed to the Google Groups "actionHero.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to actionhero-j...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages