每当我在浏览器中手动输入一个url到一个使用角构建的站点时,我就会得到:
'HTTP 404
The resource cannot be found
Requested URL: /register'唯一可导航的url是http://localhost:XXXX/index.html,从那里我必须使用锚标记在站点周围导航。
我的角配置文件如下所示:
app.config(function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
//.hashPrefix('!')
$routeProvider
.when('/', {
templateUrl: '/Client/AngularViews/home.html'
})
.when('/register', {
templateUrl: '/Client/AngularViews/register.html',
controller: 'registerController'
})
.when('/post-register', {
templateUrl: '/Client/AngularViews/postRegister.html',
controller: 'registerController'
})
.otherwise({ templateUrl: 'Client/AngularViews/home.html' });
});Index.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" data-ng-app="app">
<head>
<script type="text/javascript" src="Scripts/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="Scripts/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript" src="Scripts/mainController.js"></script>
<base href="/" />
</head>
<body>
<div class="container-fluid">
<div ng-view></div>
</div>有人能向我解释我做错了什么吗?我希望能够手动在地址栏中输入urls,并导航到index.html以外的任何东西。
发布于 2014-11-25 22:38:07
根据文件:
使用这种模式的服务器端需要在服务器端重写,基本上您必须重写到应用程序入口点的所有链接(例如index.html)。在这种情况下,需要标记也很重要,因为它允许角区分url中的应用程序基部分和应用程序应该处理的路径。
https://docs.angularjs.org/guide/$location
因此,您需要服务器端的一些额外支持:配置您的http服务器,以便为您的应用程序中的所有url提供index.html应答。
发布于 2016-02-08 04:06:45
我使用ASP.Net MVC进行服务器端的URL重写,使用控制器。可能不是它的预期用途,但效果很好。
https://stackoverflow.com/questions/27137949
复制相似问题