Following is my code where I am configuring my routes:
/**
* Main AngularJS Web Application
*/
var app = angular.module('chocomelte', [
'ngRoute'
]);
/**
* Configure the Routes
*/
app
.controller('HomeCtrl',HomeCtrl)
.controller('AboutCtrl',AboutCtrl)
.config(['$routeProvider','$locationProvider', function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when("/", {
templateUrl: "partials/home.html",
controller: "HomeCtrl"
})
.when("/about", {
templateUrl: "partials/about.html",
controller: "AboutCtrl"
})
}]);
这会从我的网址中删除#。当我尝试通过点击我的UI中的按钮转到/ about路线时,它工作正常。但是当我手动尝试键入URL并转到它或刷新/关于url的页面时,我收到此错误: 500内部服务器错误。 我没有在后端使用节点。一个在前端使用角度的简单网站。如何在客户端配置?
答案 0 :(得分:4)
确保您使用此元标记设置基本网址:
<base href="/my-base">
此外,在使用html5模式时,您可能必须在服务器上实施URL重写,以确保将任何请求重定向到应用程序的根目录,而不是被解释为GET请求。
使用此模式需要在服务器端重写URL,基本上您必须重写所有指向应用程序入口点的链接
答案 1 :(得分:1)
我正在使用Apache服务器。最后修好了。不得不重写.htaccess文件中的URL,如下所示:
Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>
必须指定index.html作为入口点。