I am using the following url in my state:

    .state('forum.spesific', {
      url: '/:articleId',
      templateUrl: 'modules/forum/client/views/forum.client.view.html',
      controller: 'forumController',
      controllerAs: 'vm',
    })
.state('forum.spesific2', {
      url: '/:articleId',
      templateUrl: 'modules/forum/client/views/forum2.client.view.html',
      controller: 'forumController',
      controllerAs: 'vm',
    })

how can i make one of them rely on that the :articleId is only number, and the other mix of numbers and characters?

like:

  .state('forum.spesific', {
          url: '/:articleId ONLY BY NUMBER',
          templateUrl: 'modules/forum/client/views/forum.client.view.html',
          controller: 'forumController',
          controllerAs: 'vm',
        })
    .state('forum.spesific', {
          url: '/:articleId BOTH ( have to be both)',
          templateUrl: 'modules/forum/client/views/forum2.client.view.html',
          controller: 'forumController',
          controllerAs: 'vm',
        })
share|improve this question

you can use the regex-like syntax: '/articles/{id:int}', that matches only integers. By the way, this is not very-safe because id (eg: bigInt) can be out of the javascript safe integer range... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger

share|improve this answer
    
so in this case it would be /:articleid:int , then articleid would be within int? what about the other? would that work with a string? – maria 12 mins ago
    
you just need to put the {mixed} param route after the {int} param route. – Hitmands 11 mins ago

you can specify regex like so:

 .state('forum.spesific', {
      url: '/{articleId:[0-9]+}',
      templateUrl: 'modules/forum/client/views/forum.client.view.html',
      controller: 'forumController',
      controllerAs: 'vm',
    })
.state('forum.spesific2', {
      url: '/:articleId',
      templateUrl: 'modules/forum/client/views/forum2.client.view.html',
      controller: 'forumController',
      controllerAs: 'vm',
    })

but why 2 states if the only difference is the id type ?

share|improve this answer
    
@DMISSOKHO , thats because im relying on if the id is a number or a mixed one. mixed one will show a topic, when number will show page number . but wouldnt spesific2 match the forum.spesific too, the 2nd state would be true on both? – maria 9 mins ago

Maybe you can merge those 2 states into the same and change the templateUrl

templateUrl: function (stateParams){ if(isNaN(stateParams.articleId)){ return "modules/forum/client/views/forum2.client.view.html" } else { return "modules/forum/client/views/forum.client.view.html"; } }

Hope this helps

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.