0
我使用Yeoman包管理器来创建一个角度的web应用程序。这是我的主控制器:apache的AngularJS路由问题
'use strict';
angular
.module('resFourApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.when('/contact', {
templateUrl: 'views/contact.html',
controller: 'ContactCtrl'
})
.otherwise({ redirectTo: '/' });
// use the HTML5 History API
// use the HTML5 History API
$locationProvider.html5Mode(true);
});
如果我从基本目录访问应用程序,但如果我从URL访问它,去www.base.com/route我得到一个404错误,工作正常。我理解的是因为Angular是一个客户端应用程序,所以服务器上没有任何东西可以处理这些请求。我已经阅读了很多关于必须重新路由服务器或mod用apache重写的内容,但是我仍然没有得到它的工作。
事情我已经试过
Apache rewrite rules not being applied for angularjs
https://groups.google.com/forum/#!msg/angular/GmNiNVyvonk/mmffPbIcnRoJ
我的Apache Web服务器的.htaccess:
# BEGIN angularJS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.html/#/$1
</IfModule>
# END angularJS