【发布时间】:2013-07-28 13:32:57
【问题描述】:
每次我都会收到 404 页面:
1.)刷新我的Angularjs网站上的任何页面(除了根页面)
或
2.)点击Back从404页面转到根页面(根页面将是404) p>
这是我的.config() 代码
'use strict';
angular.module('mmApp', ['ngResponsiveImages'])
.config(function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix = '!';
$routeProvider
.when('/', {
templateUrl: '/views/design.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: '/views/about.html',
controller: 'MainCtrl'
})
.when('/contact', {
templateUrl: '/views/contact.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
});
我遇到过这个类似的问题,但不太明白答案或如何实现它们。
AngularJS - Why when changing url address $routeProvider doesn't seem to work and I get a 404 error
接受的答案是设置 Apache 以重新配置到根目录的所有路径。我的网站在 Github Pages 上。我的gh-pages 存储库中有一个.htaccess 文件,但我不知道如何配置它以将所有路径发送到根目录。
答案说要考虑的另一件事是使用<base> 元素,如<base href="/" />,但我应该把它放在哪里?在我的index.html?如果是在该文件的顶部或底部?另外,我可以将href 的值留给/ 吗?
【问题讨论】:
-
你设置html5mode为false有这个问题吗?
-
我刚刚测试了我的网站,将 html5Mode 设置为 false,就像
$locationProvider.html5Mode(false);一样,但问题仍然存在。
标签: .htaccess angularjs github http-status-code-404 github-pages