Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

What is a nice way to match url for both /url.html and /url.html/ in Angular.js ui-router?

For now, they are separate like this in my code:

  $stateProvider
    .state("myUrl1", {
      url: "/",
      resolve: {
        init: function() {
          console.log("Triggered resolve myUrl1 /");
          return true;
        }
      }
    })
    .state("myUrl2", {
      url: "^",
      resolve: {
        init: function() {
          console.log("Triggered resolve myUrl2");
          return true;
        }
      }
    });

I have tried [^/]*} in the doc https://github.com/angular-ui/ui-router/wiki/URL-Routing but no success.

Any pointer?

share|improve this question
    
$routeProvider.when do for both automatically though. –  YOU Jan 3 at 7:50
    
may be add [/]* at the end or if it is regex adding \/? should work. –  YOU Jan 3 at 7:52
    
^[/]* doesn't work (not being called at all) and ^\/? gave me error Invalid parameter name '' in pattern '/?' –  HP. Jan 4 at 0:03
    
ok, its not regex then –  YOU Jan 4 at 5:31

1 Answer 1

AngularUI Router is a routing framework for AngularJS, which allows you to organize the parts of your interface into a state machine. Unlike the $route service in Angular core, which is organized around URL routes, UI-Router is organized around states, which may optionally have routes, as well as other behavior, attached.

You are asking about how to implement a URL route using a plugin that is not designed for handling routes in this way. If you are only interested in URL routing, you should use the Angular core $routeProvider.

http://docs.angularjs.org/api/ngRoute

Also, Angular routes don't normally include .html. And, your two example routes /url.html and /url.html/ appear to be semantically the same.

share|improve this answer
    
I am interested in both state and routing. The two examples are more for production vs. development. In production, url is like /url/ and in development (with light weight Middleman server), the url is /url.html instead. I think it should be the same and trigger same state but it doesn't do that. I will check out @YOU RegEx advise. –  HP. Jan 4 at 0:01

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.