Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route patterns optional parameters? (Updated to Request) #43

Open
andrewcrook opened this issue Jun 19, 2013 · 1 comment
Open

Route patterns optional parameters? (Updated to Request) #43

andrewcrook opened this issue Jun 19, 2013 · 1 comment

Comments

@andrewcrook
Copy link

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?

@andrewcrook
Copy link
Author

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.

@16 16 added the Enhancement label Jun 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants