1

I'm using AnglarJs and Angular UI Router for my project. I'm using parameters for my route such as:

url: '/content/:categoryId/:categoryType'

But I got problem when using url:

url: '/content/detail/:contentId'

It seem Angular UI Router can not recognize the difference of these 2. Then I decide to use regexp parameter for all of them

url: '/content/{categoryId:int}/{categoryType:int}'
url: '/content/detail/{contentId:int}'

The second url is ok but Angular UI Router can not recognize the first one when I using ui-sref:

<a ui-sref="firstUrl({categoryId: 1, categoryType: 2})">Anchor</a>

Was Angular UI router support just one regexp parameter?

2
  • 1
    Usually it's a good idea to start with the 'static' ones and the dynamic urls later to avoid conflicts. Try putting the 'detail' one first. Commented Mar 11, 2015 at 3:58
  • Thank you very much! By rearrange order of routes, I've solve my problem. Commented Mar 11, 2015 at 4:22

1 Answer 1

1

The issue here is in the way how UI-Router is finding/resolving state for url. It uses:

  • the order of state defintion
  • first matching is used

And that is in fact the issue, because first url pattern:

url: '/content/{categoryId:int}/{categoryType:int}'

is absolutely suitable for the url provided for this one

url: '/content/detail/{contentId:int}'

Solution in these cases is relatively simple. Change the order of state definitions. The more precise should go first, the more dynamic second

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.