在阅读了有关 Angular.js 路线的大量文章和 stackoverflow 问题后,当我进行手动刷新时,我仍然收到“未找到”错误。
Steps:
- 浏览到
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'
});
}
]);
我做过的其他事情:
- In my
index.html
,我已经有了<base href="/">
- 升级到角度1.2.1
这是我尝试过的 htaccess 规则。没有工作。
from 刷新页面提示“找不到页面”
<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>
from 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>