在阅读了大量关于 Angular.js 路由的文章和 stackoverflow 问题后,当我手动刷新时,我仍然收到“未找到”错误。
脚步:
- 浏览到
localhost
--> 由于我的配置(如下),我被带到localhost/home
. 视图和一切都加载正常。 - 在浏览器中点击刷新 --> 浏览器显示这个
Not Found: the requested /home is not found on this server
这个问题可能最像刷新页面给出“找不到页面”
我的配置
// Routing configuration.
angular.module('myModule')
.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
// Enable pushState in routes.
$locationProvider.html5Mode(true);
$routeProvider
.when('/home', {
templates: {
layout: '/views/home.html'
},
title: 'Welcome!'
})
.when('/launchpad', {
templates: {
layout: '/views/layouts/default.html',
content: '/views/partials/profile.html'
},
title: "Launchpad"
})
.otherwise({
redirectTo: '/home'
});
}
]);
我做过的其他事情:
- 在我的
index.html
,我已经有了<base href="/">
- 升级到角度 1.2.1
这是我尝试过的 htaccess 规则。没有工作。
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteCond %{REQUEST_URI} !.*\.(css|js|html|png) #Add extra extensions needed.
RewriteRule (.*) index.html [L]
</ifModule>
来自http://ericduran.io/2013/05/31/angular-html5Mode-with-yeoman/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.html/#!/$1
</IfModule>