olivernn / davis.js

RESTful degradable JavaScript routing using pushState
http://davisjs.com
532 stars 58 forks source link

Wild card patterns for paths #37

Closed agentgt closed 12 years ago

agentgt commented 12 years ago

From what I gather is no wild card path support right? In other words you can't do something like the following:.

    var app = Davis(function () {
      this.get('/welcome/**', function (req) {
        alert("Hello " + req.params['name'])
      })
    })

"**" in this case means all paths and subpaths underneath '/wecome/' an example implementation in Java is here: http://static.springsource.org/spring-security/site/docs/3.1.x/apidocs/org/springframework/security/web/util/AntPathRequestMatcher.html

olivernn commented 12 years ago

In the current 0.8.x version there is no support for wildcard route matching, however I have already added it to what will become version 0.9.x in the next branch.

It could change an any time yet but currently the api looks like this:

this.get('/welcome/*name', function () {
  console.log(req.params['name'])
})

As you would expect this will match the following:

/welcome/foo
/welcome/foo/bar/baz

If all goes well I should be able to put together a release next week.

marcuslindblom commented 12 years ago

Is it possible to do something like this

this.get('/pages/[this-can-be-one-slug/or-maybe-two/or-as-many-as-i-like]/edit', function (req) {
 alert('Editing: ' + req.params[the slugs]);
})
olivernn commented 12 years ago

@kloojed that would work because the string gets turned into a regex. The new release will have support for this, I'm hoping to get a release out early next week, travelling has delayed it a little,

olivernn commented 12 years ago

Added in version 0.9.0

raags commented 12 years ago

Ah, luckily Google led me to this page. Could you put these feature in the documentation?

olivernn commented 12 years ago

Good call, I'll get this added to the site and api docs, thanks for bring it to my attention

joelgalvez commented 10 years ago

on 0.99, how do I name and access the second segment?

'/page/[one/two/three]/:somevalue'

i've tried

'/page/[one/two/three]:thing/:somevalue' '/page/([one/two/three]):thing/:somevalue'

etc...