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

Type annotations for URLs #2641

Closed
jjvattamattom opened this issue Dec 4, 2015 · 1 comment
Closed

Type annotations for URLs #2641

jjvattamattom opened this issue Dec 4, 2015 · 1 comment

Comments

@jjvattamattom
Copy link

I guess having type annotation on route parameters is helpful for two reasons.

A request for /users/staff hits the first second route instead of the third.

<Route path="/users" component={}/>
<Route path="/users/:id" component={}/>
<Route path="/users/staff" component={}>

Having annotations like <Route path="/users/<id:int>"/> could have prevented this.

I have to arrange stuff like:

<Route path="/users" component={}/>
<Route path="/users/staff/x" component={}>
<Route path="/users/staff/y" component={}>
<Route path="/users/staff/z" component={}>
<Route path="/users/:id" component={}/>

Also I have to manually check the type of the params. I have a component for /users/:numericId, I have to check if numericId is an integer, and to redirect to 404 page if its not.

The router should not match /users/:numericId if /users/apha were provided.

As an example of type annotations for route params, Flask (server-side Python web framework) allows this:

@app.route('/user/<username>') # string
@app.route('/post/<int:post_id>')
@app.route('/post/<float:post_id>')
@app.route('/post/<path:post_id>')
@taion taion added the duplicate label Dec 4, 2015
@taion
Copy link
Contributor

taion commented Dec 4, 2015

#2286 starts exactly from the Flask thing, although we're at a bit of a different place now.

@taion taion closed this as completed Dec 4, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants