用户界面路由器&x27;s$urlRouterProvider.OTHES与HTML5模式
考虑以下来自UIRouter的wiki的稍加修改的代码用户界面路由器&x27;s$urlRouterProvider.OTHES与HTML5模式,html,angularjs,angular-ui-router,Html,Angularjs,Angular Ui Router,考虑以下来自UIRouter的wiki的稍加修改的代码 var myApp = angular.module('myApp',['ui.router']); myApp.config(function($stateProvider, $urlRouterProvider, $locationProvider) { // for any unmatched url $urlRouterProvider.otherwise("/state1"); $locationPro
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"];
}
})
});
在运行Python3的SimpleHttpServer时,我在尝试访问时遇到了一个404错误:http://localhost:8000/state1234324324
为什么不$urlRouterProvider.否则(“/state1”)
将所有未知路由重新定向到/state1
,根据这一点,该路由具有与/state1
url关联的已定义的状态
。这是因为当您使用类似“/state123413”的url点击服务器时,它将直接返回404响应(客户端不会发生路由)
你需要做的是制定一条全面的路线。e、 g在快车上你能做什么
app.get('/*', function(req, res){
res.render('defaulttemplate')
}
这将在客户端强制路由。请参阅普通服务器的ui路由器以设置catchall路由。为什么ui路由器不能正常工作?自从我添加了修复程序后,我的路由就不起作用了,尽管其他方法现在起作用了。。。