我在我的AngularJS应用程序中使用Html5Mode(true)
。当我以以下方式浏览我的网站时,这很有效:
http://www.example.com
这将被转换为:
http://www.example.com/home/index
我的页面正常渲染。但是,当我按 F5 键时,控制台窗口中会出现很多错误信息:
Resource interpreted as Script but transferred with MIME type text/html: "http://www.example.com/home/js/jquery/jquery.min.js". index:22
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://www.example.com/home/js/slider/angular.rangeSlider.css". index:16
Uncaught SyntaxError: Unexpected token < jquery.min.js:1
Resource interpreted as Script but transferred with MIME type text/html: "http://www.example.com/home/js/angular/angular-resource.min.js". index:25
Resource interpreted as Script but transferred with MIME type text/html: "http://www.example.com/home/js/angular/angular.min.js". index:24
Uncaught SyntaxError: Unexpected token < angular.min.js:1
Uncaught SyntaxError: Unexpected token < angular-resource.min.js:1
Resource interpreted as Script but transferred with MIME type text/html: "http://www.example.com/home/js/angular/angular-cookies.min.js". index:26
Uncaught SyntaxError: Unexpected token <
我已经按照以下方式配置了我的
.htaccess
文件:RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^(.*) /index.html [L]
但是当我刷新页面时,这个方法就失效了,我会收到错误提示。我是使用“ui-router”,但不确定是否有所不同。我的路由设置看起来像这样:
$locationProvider.html5Mode(true);
$urlRouterProvider.otherwise('/home/index');
$stateProvider
.state('home', {
abstract: true,
url: '/home',
templateUrl: '/tpl/home.html'
})
.state('home.index', {
url: '/index',
templateUrl: '/tpl/home_index.html'
})
有人知道为什么刷新页面会导致我上面发布的错误吗?