Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Add "types" to path matchers. #24

Closed
mthadley opened this issue Dec 4, 2017 · 4 comments
Closed

Add "types" to path matchers. #24

mthadley opened this issue Dec 4, 2017 · 4 comments

Comments

@mthadley
Copy link

mthadley commented Dec 4, 2017

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

jbalsas commented Dec 5, 2017

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?

@mthadley
Copy link
Author

mthadley commented Dec 5, 2017

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

@robframpton
Copy link
Contributor

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?

@jbalsas
Copy link
Contributor

jbalsas commented Jan 24, 2018

Moved to metal/metal-plugins#13

@jbalsas jbalsas closed this as completed Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants