【发布时间】:2014-06-07 02:02:36
【问题描述】:
考虑以下来自 ui-router 的 wiki 的稍作修改的代码。
var myApp = angular.module('myApp',['ui.router']);
myApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
// for any unmatched url
$urlRouterProvider.otherwise("/state1");
$locationProvider.html5Mode(true);
// now set up the states
$stateProvider
.state('state1', {
url: '/state1',
templateUrl: "partials/state1.html"
})
.state('state1.list', {
url: "/list",
templateUrl: "partials/state1.list.html",
controller: function($scope) {
$scope.items = ["A", "List", "of", "Items"];
}
})
.state('state2', {
url: "/state2",
templateUrl: "partials/state2.list.html",
controller: function($scope) {
$scope.things = ["a", "set", "of", "things"];
}
})
});
运行 python 3 的 SimpleHttpServer,我在尝试访问时得到一个 404 error:http://localhost:8000/state1234324324。
为什么$urlRouterProvider.otherwise("/state1"); 不将所有未知路由重定向到/state1,因为question 有一个与/state1 url 关联的已定义state?
【问题讨论】:
标签: html angularjs angular-ui-router