sofadesign/limonade

Route patterns optional parameters? (Updated to Request)

andrewcrook opened this issue · 1 comments

I apologise for asking this here but I didn't know where else to ask.

Can route patterns have an optional parameter for example a page number encoded as apart of the route?

For example to merge these two dispatches ..

dispatch('/blog/:slug','blog')
dispatch('/blog/:slug/:page', 'blog')

If so please can an example be added to the documentation regarding route patterns and parameters?

As I wanted to replace the slug parameter with the double wildcard character for more complex slugs I thought I would get around this by replacing it with a regular expression. This works well but I have found a small issue regarding parameters which I will post under a separate issue sometime, although I got around the issue with some code in the controller it's a bit messy. I do still think optional parameters will be a good idea for some developers and on other projects, May I suggest the following syntax?

$options = array('params' => array('page'=>0));
dispatch('/blog/:slug(/:page)', 'blog', $options );

Another example for better optional trailing slash support by using nesting

$options = array('params' => array('page'=>0));
dispatch('/blog/:slug(/(:page(/)))', 'blog', $options );

As you can see this doesn't have to be limited to parameters.