-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($route): express style route matching #1745
Conversation
If you want your pull requests to be accepted, you need to add tests, change your commit message and sign CLA as described here: http://docs.angularjs.org/misc/contribute |
The commit has tests and I signed the CLA yesterday. |
You still need to change the commit message. Just letting you know. I had to go through the same process. |
what do you mean by change the commit message? |
Thanks for the help. Is there anything else I'm missing? |
No problem. I think that's it, nothing else missing. |
this is the feature I'm waiting for, why you are not merge it in? |
+1 how long is needed to merge it? |
* @methodOf ng$routeProvider | ||
* | ||
* @description | ||
* Options fore route matching. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo "fore" => "for"
|
@joshrtay - this PR is now a bit outdated and it is difficult to rebase against the current master. Can you take a look at this please? |
ya i'll update it. |
it looks like the way you guys have implemented wildcards is incompatible with the way express does it. wildcards in express are unnamed. how would you like me to proceed? |
@joshrtay thanks for doing this. Let's add only optional params for now and merge it in. I think having named wildchars is more expressive so I would prefer keeping that. That means, you can't do stuff like .when('user/:id.:format')
// /user/10.json -> {id: '10', format: 'json'} If we wanna get super crazy, we could later allow regexp matching as well: .when('/user/:id(\d)'
// /user/23 -> {id: 23}
// /user/x would not match But at that point, allowing a custom match function rather than a string would be probably better. Guys @xrado @NSS do you have any other use case that is missing ? |
optional params are the only thing I miss |
optional params working |
Long waited feature, definitely 👍 |
|
||
$location.path('/bar/foovalue'); | ||
$rootScope.$digest(); | ||
expect($routeParams).toEqual({foo: 'foovalue'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test that even without the optional value the route still matches - currently you are only checking the routeParams I was thinking that we should check the current route to see that it has been matched correctly but I guess that this is implicit.
What about paths that don't just end in an optional parameter?
/bar/:foo?/edit
-> will this match /bar/fooValue/edit
and /bar/edit
?
- We should have tests of these cases for both ? and * style optional parameters.
I'm not sure what you mean by the routes still match, but I added some more routeParams tests. Also, my implementation supports this: .when('user/:id.:format')
// /user/10.json -> {id: '10', format: 'json'} I think that named wildcards should be considered very carefully, since it seems to go against wildcard convention. Most people would assume that Unnamed wildcards, though not as expressive, are more consistent with how wildcards typically work and you can still access the values by position. |
@joshrtay & @vojtajina - I kind of agree that the named wildcard format is not so intuitive. I wonder if it would be clearer to use a similar convention to the optional parameter:
would match |
In the meantime I think we are about there to merge this. |
@joshrtay - sorry but IE doesn't like your code: http://ci.angularjs.org/job/angular.js-pete/139/console :-( |
@petebacondarwin - i dont have a great way of testing on IE. any thoughts on what is causing the errors? |
My thought was that these are not like unordered params so optionalParam2 Pete
|
@IgorMinar that proposal sounds good. I think we should allow |
ok, I'm fine with can we move forward and making the code change? |
i'll do it this weekend. |
* | ||
* For example, routes like `/color/:color/largecode/*largecode/edit` will match | ||
* For example, routes like `/color/:color/largecode/:largecode*\/edit` will match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had to add \ so */ didn't end the comment. will this be a problem for the docs?
code changes were made. let me know what you think. |
Added new route matching capabilities: - optional param Changed route matching syntax: - named wildcard
sorry that last commit wasn't rebased against master |
@IgorMinar waiting for some input on the changes ... would you like me to submit the syntax change to wildcard params as a new pull request? |
I am seeing a few test failures on this PR.
Investigating further.
|
where are you seeing those test failures? as far as I can tell, all the tests are passing. |
All tests are passing for me when I rebase this CL; it could have been my environment. |
* | ||
* For example, routes like `/color/:color/largecode/*largecode/edit` will match | ||
* For example, routes like `/color/:color/largecode/:largecode*\/edit` will match |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the backslash before /edit belong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i want it to read /color/:color/largecode/:largecode*/edit
, but the */
ends the comment. what should i do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! I missed that.
I added a few more test and fixed the style comments in https://github.com/jbdeboer/angular.js/tree/pr1745 Looks good to merge and I will do the merge shortly. |
Hmm; taking another look at this PR: @IgorMinar's spec said "an optional param cannot be be followed by a string literal, required or wildcard param" There doesn't seem to be any code that enforced that requirement. The tests check for this case explicitly: '/test/:opt?/:baz/edit Should we add an explicit check for trailing parameters after an optional? |
Is that something we really want to enforce? It seems ugly, but it is On Friday, August 9, 2013, James deBoer wrote:
|
I would like to hear from @IgorMinar, @petebacondarwin or @vojtajina who were involved in the discussion about literals or required parameters after an optional parameter and have more context. Re-reading the discussion, the justification for optional parameters seems thin. I see it is a convenience in some situations. However, using optional parameters moves routing decisions out of the route declaration and into controllers (e.g. I can imagine code that checks for an empty optional parameter and then loads a completely different view). By banning required parameters and string literals after the optional parameters, we would be purposely limited the power, and thus the abuse, of optional parameters. On the other hand, there is no technical reason for such a ban. Getting this feature into the hands of developers would help us understand how they use it. |
@jbdeboer no problem. glad to help. |
visionmedia/express style route matching: