How to match a route containing parameters

314 views
Skip to first unread message

j...@illumi.dk

unread,
Nov 18, 2015, 3:17:23 AM11/18/15
to Sammy.js
If i want to match a route that looks like this

/path?searchTerm=something

How do i do that?

I've tried these, but they don't work

Sammy(function() { this.get("/path%3F:param", function () {...}); }).run();


Sammy(function() { this.get("/path/?:param", function () {...}); }).run();

Sammy(function() { this.get("/path?:param", function () {...}); }).run();

Aaron Quint

unread,
Nov 18, 2015, 10:03:43 AM11/18/15
to sam...@googlegroups.com
Routes will only match paths, params/query strings are always stripped before matching. You can either convert to a path

e.g. get('/path/search/:term', ...)

or check the search inside the route body

get('/path', function() {
  if (this.params['searchTerm'] == 'search') {
...
 }
})

--AQ

--
You received this message because you are subscribed to the Google Groups "Sammy.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sammyjs+u...@googlegroups.com.
To post to this group, send email to sam...@googlegroups.com.
Visit this group at http://groups.google.com/group/sammyjs.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages