Discussion: Match the most specific URL, not the first found #15

christopherthielen opened this Issue Dec 16, 2016 · 1 comment


None yet

1 participant


Currently if you register states with urls like:

.state('foo', {
  url: '/foo/:fooid',
  params: { bar: null, squash: true }
.state('foo.bar', {
  url: '/staticstring'
.state('foo2', {
  url: '/foo/otherstring'

With URL /foo/staticstring, foo is matched because it matches the pattern and its url rule was registered first. Currently, the first matched URL always wins.

Likewise, with URL /foo/otherstring, foo is matched for the same reasons.

Choose most specific match

Consider implementing heuristics where the most specific match is chosen.

  • For url: /foo/staticstringwe should detect that foo.bar is more specific than foo.
    • Deepest state wins
  • For url: /foo/otherstring we should detect that foo2 is more specific than foo.
    • Fewer parameters win?

This would have the additional benefit during lazy loading. When states are lazy loaded, there might not be a guarantee of the load order, so less specific urls could be registered before more specific ones.

@christopherthielen christopherthielen added this to the 3.0.0 milestone Jan 4, 2017

Closed by eb2f5d7

@christopherthielen christopherthielen added a commit that referenced this issue Jan 7, 2017
@christopherthielen christopherthielen fix(Transition): Use { location: replace } when redirecting a transti…
…tion in response to a URL sync

This fixes a problem that occurred when the url sync caused a redirection:

- URL changes (to `/foo`)
- Router synchronizes
- Router redirects elsewhere (to `/bar`)
- Url is updated

Now the browser history has two history entries:

- `/foo`
- `/bar`


Now, when the URL is updated, it uses `{ location: replace }` so the browser history only has one entry:

- `/bar`

Closes angular-ui/ui-router#3187
Closes #15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment