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

Add "types" to path matchers #13

Open
jbalsas opened this issue Jan 24, 2018 · 4 comments
Open

Add "types" to path matchers #13

jbalsas opened this issue Jan 24, 2018 · 4 comments

Comments

@jbalsas
Copy link
Contributor

jbalsas commented Jan 24, 2018

Copied from deprecate/metal-router#24 by @mthadley

Hey everyone, I wanted to throw out a quick idea that may reduce some of the boilerplate when defining our routes.

It's pretty common to define a route like this, possibly many times, that is meant to match some kind of number:

<Route
  component={userPage}
  path="user/:id(\d+)/"
/>

After a while, it get's tedious to add these regexes to our routes, and also reduces readability. Maybe instead we could still allow for a regex, but also provide some default "types":

<Route
  component={userPage}
  path="user/:id<number>/"
/>

The syntax is subject to change, but I think it would at least be useful for parsing numbers. Possible other things like booleans as well.

Thanks!

@jbalsas
Copy link
Contributor Author

jbalsas commented Jan 24, 2018

Copied from deprecate/metal-router#24 by @jbalsas

Hey @mthadley, this does indeed seem interesting, but I haven't been able to find a similar approach out there int he wild. All of them seem to just rely on regexes for this.

I'd be more comfortable if there is already a pattern for this out there, so we don't need to come up with our own format. Do you know of any such cases?

@jbalsas
Copy link
Contributor Author

jbalsas commented Jan 24, 2018

Copied from deprecate/metal-router#24 (comment) by @mthadley

@jbalsas Yea! So Django recently added something like this. Check it out here.

@jbalsas
Copy link
Contributor Author

jbalsas commented Jan 24, 2018

Copied from deprecate/metal-router#24 (comment) by @Robert-Frampton

This would actually mean changing Senna and https://github.com/metal/metal-path-parser.

@brunobasto, what are your thoughts on this behavior for the Senna Route class?

@brunobasto
Copy link

Hey guys, I might have missed this thread. I like the idea. If everyone agrees, we can try to add support for it. We should probably do it in way that's backwards compatible thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants