Angularjs 使用HTML5模式刷新页面时出现意外标记

Angularjs 使用HTML5模式刷新页面时出现意外标记,angularjs,.htaccess,angular-ui-router,Angularjs,.htaccess,Angular Ui Router,我正在AngularJS应用程序中使用HTML5模式(true)。当我像这样浏览我的网站时,这很好: http://www.example.com RewriteEngine on # Don't rewrite files or directories RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] # Rewrite everything el

我正在AngularJS应用程序中使用
HTML5模式(true)
。当我像这样浏览我的网站时,这很好:

http://www.example.com
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]
$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'
    })
然后将其转换为:

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 < 
但当我刷新页面时,这不起作用。然后我会出错。有什么我遗漏的吗


我正在使用
ui路由器
。不确定这是否有什么不同。我的路线是这样的:

http://www.example.com
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]
$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'
    })

有人知道为什么刷新页面会导致我上面发布的错误吗?

您应该只重写所需的路由器URL,例如:

/home-index.html

/product/1234-index.html


不要将所有请求重写到index.html。因为大多数URL都不应该被重写

我刚刚找到了解决办法。问题是您正在重写到服务器的所有路径。您需要创建规则以排除文件夹内容和脚本