Skip to content

Route priority #1277

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

Closed
macalinao opened this issue Aug 19, 2014 · 16 comments
Closed

Route priority #1277

macalinao opened this issue Aug 19, 2014 · 16 comments

Comments

@macalinao
Copy link

GitHub has its /settings route with a higher priority than the /:username route. Is this possible with ui-router? I wasn't able to find any documentation on it. Thanks.

@christopherthielen
Copy link
Contributor

I believe routes are matched in the order they are defined. However, exact matches take precedence over parameterized matches.

@macalinao
Copy link
Author

Is there a way to supply a number for priority? I can't specify the order
of the files beforehand as I am using an injection script.
On Aug 26, 2014 6:59 PM, "Chris Thielen" [email protected] wrote:

I believe routes are matched in the order they are defined. However, exact
matches take precedence over parameterized matches.


Reply to this email directly or view it on GitHub
#1277 (comment)
.

@christopherthielen
Copy link
Contributor

no, sorry, not currently possible.

@orrgal1
Copy link

orrgal1 commented Jun 14, 2015

it doesn't look like exact matches have a higher priority...

@christopherthielen
Copy link
Contributor

@orrgal1 I could have been wrong about that, sorry. I'm not sure if we have specified that behavior

@orrgal1
Copy link

orrgal1 commented Jun 16, 2015

no worries thanks, just wanted to make sure

On Tue, Jun 16, 2015 at 4:30 AM, Chris Thielen [email protected]
wrote:

@orrgal1 https://github.com/orrgal1 I could have been wrong about that,
sorry. I'm not sure if we have specified that behavior


Reply to this email directly or view it on GitHub
#1277 (comment)
.

@plong0
Copy link

plong0 commented Oct 26, 2015

Found a solution here: http://stackoverflow.com/questions/26389177/angularjs-ui-router-incorrectly-interpreting-url-path-as-paremeter-in-urlroute

Explicitly defining the higher priority route in the $urlRouterProvider works.

ex:

$stateProvider.state('foo.bar', {url: '/foo/:bar'});
$stateProvider.state('foo.baz', {url: '/foo/baz'});
$urlRouterProvider.when( '/foo/baz', function($state){ $state.go('foo.baz'); } );

@aeharding
Copy link

I also have this problem. It would be nice if routes declared earlier had priority, or there was some sort of smart detection to see which route is more general.

Is this fixed in ui-router 2?

Just to show what routes were giving me trouble:

/contact/new
/contact/:id

In this case, /contact/:id is always chosen by ui-router. Switching it around gets the desired functionality... But only sometimes. ;)

@christopherthielen
Copy link
Contributor

@aeharding what version of ui-router are you on? I think we merged in a PR that tries to prioritize urls based on the length of the prefix (params don't count as prefix)

b5c57c8

@pietro909
Copy link

Hi, I ran into the same issue and this is what I found so far:

Is there any news about it?
thanks

@nateabele
Copy link
Contributor

We have a naïve sorting implementation that is currently broken in 1.0alpha0 but is being patched in alpha1. We plan to expose an API for managing sort order at some point down the road in 1.0.

@aeharding
Copy link

@christopherthielen I tried upgrading to that release, but unfortunately, it did not fix the problem. I ended up switching the order of the state declaration, but I still think /contact/new being declared before /contact/:id should ideally catch the route.

Good to hear that v1 might fix this. 👍

@christopherthielen
Copy link
Contributor

See #2502

@rkingon
Copy link

rkingon commented Jun 8, 2016

If you're using a numerical id vs a string slug then you can use regex on the id param like so: url: "/{id:[0-9]+}". It will only match numerical id's and allow new to route correctly.

@toxaq
Copy link

toxaq commented Aug 28, 2017

Was this resolved at all? I couldn't tell from 2502... I've just found this issue with nest params on 1.0.3

/:parent_id/child/new       
/:parent_id/child/:id

The new route was unreachable.

@stale
Copy link

stale bot commented Jan 24, 2020

This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs.

This does not mean that the issue is invalid. Valid issues
may be reopened.

Thank you for your contributions.

@stale stale bot added the stale label Jan 24, 2020
@stale stale bot closed this as completed Feb 7, 2020
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

9 participants