0

I need to be able to pass this 2 routes in AngularJS :

.state('app.article', {
     url: '/:catName/:articleName',
     views: {
         'menuContent': {
             templateUrl: 'templates/article.html',
             controller: 'ArticleCtrl'
         }
     }
 })

 .state('app.category', {
     url: '/:catName/:subcatName',
     views: {
         'menuContent': {
             templateUrl: 'templates/category.html',
             controller: 'CategoryCtrl'
         }
     }
 })

The problem is that they are both quite the same.

The only differance I do have is that an article name is ending with a -XXXXXX where XXXXXX is a number.

How can I do that?

thanks.

1 Answer 1

1

You need to include some way to differentiate these routes. Here is one approach

.state('app.article', {
     url: '/:catName/article/:articleName',
     views: {
         'menuContent': {
             templateUrl: 'templates/article.html',
             controller: 'ArticleCtrl'
         }
     }
 })

 .state('app.category', {
     url: '/:catName/category/:subcatName',
     views: {
         'menuContent': {
             templateUrl: 'templates/category.html',
             controller: 'CategoryCtrl'
         }
     }
 })
Sign up to request clarification or add additional context in comments.

2 Comments

That is not an option as the urls are coming from an external source. This is their structure and it can't be changed. Is there a way to check if the url ends with a number?
You can try something like this. Alternatively, you can use the same controller for both routes and perform different logic based on the param data

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.