我在app.js中有这个:
var myApp =
angular
.module('myApp', [ 'ngRoute' ])
// configure our routes
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl : 'partials/take.html',
controller : 'myCtrl'
})
.when('/take', {
templateUrl : 'partials/take.html',
controller : 'myCtrl'
})
.when('/part',
{templateUrl : 'partials/part.html', controller : 'myCtrl'})
.when('/program', {
templateUrl : 'partials/program.html',
controller : 'myCtrl'
})
.when(
'/forum',
{templateUrl : 'partials/forum.html', controller : 'myCtrl'})
.otherwise({redirectTo : '/'});
$locationProvider.html5Mode(true);
})
我在index.html中有这个:
...
<ng-view></ng-view>
...
<!-- angularJS -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular-route.js"></script>
<script src="js/app.js"></script>
...
我的apache2.conf文件如下:
<Directory />
Options FollowSymLinks
AllowOverride none
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www>
Options Includes
AllowOverride All
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
我的.htaccess文件包含:
<IfModule mod_rewrite.c>
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(upload|upload_cover)\.php
RewriteRule . /index.html [L]
</IfModule>
由于某些原因,muy模板不会加载到ng-view上。我在apache服务器上使用AngularJS并且index.html正在运行,但模板区域显示为空白。我在index.html中定义了<base href="/">
。我一直在谷歌搜索其他类似的问题,我使用了类似的.htaccess,但这不会工作。有人能帮助我吗?