问题
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 theboard
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