angularjs ui-router location path not recognizing the forward slahes

半世苍凉 提交于 2019-12-13 01:34:59

问题


I'm using angular ui router / stateProvider. However I set up my url any parts after the second forward slash is ignored and it always sends to this state:

  $stateProvider.state('board', {
    url: "/:board",
    views: {
      'content': {
        templateUrl: '/tmpl/board',
        controller: function($scope, $stateParams, $location) {
          console.log('wat')
          console.log($location)
        }
      }
    }
  });

Which has only 1 forward slash. Even when I go to localhost/contacts/asdf The following state doesn't run.

$stateProvider.state('test', { url: "/contacts/asdf", views: { 'main': { templateUrl: '/tmpl/contacts/asdf', controller: function () { console.log('this doesnt work here') } } } });

This is a console log of $location. As you can see $location only recognizes the last part of the url as the path. As far as I can tell that's wrong. It's missing the "contacts" right before it. Any url is interpreted as having only 1 part for the url and sends to the board state. How do I fix this. THanks.

Edit: found that this was caused by angular 1.1.5. Reverting back to 1.1.4 didn't have this.


回答1:


This may be the cause: https://github.com/angular/angular.js/issues/2799 . Try adding a base href.




回答2:


Looks like that fixed in AngularJS v1.0.7. Just tested it.



来源:https://stackoverflow.com/questions/16747170/angularjs-ui-router-location-path-not-recognizing-the-forward-slahes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!