角度路由,apache重写,浏览器缓存

时间:2016-03-11 03:24:25

标签: angularjs apache

使用角度ngroute将应用程序路由到任何所需的html文件,但只是不明白为什么当我通过单击刷新按钮或F5刷新页面时它不起作用,它给出了一个错误第404页。一直在播放.htaccess文件,但没有多大帮助。我必须返回基本目录并再次单击菜单。

如果我在页面http://localhost/test/master/material上并尝试通过点击f5来刷新页面,则会显示第404页。

另一个原因是浏览器保留了页面的缓存,有时候它没有反映我在html文件中所做的更改,它只是仍然显示旧页面,我在显示之前手动清除了缓存新的HTML。

app.js

angular.module('MyApp', ['ngRoute', 'controllers', 'ngAnimate']) 
.config(function($routeProvider, $locationProvider) {
  $routeProvider   
    .when('/master/material', {
        templateUrl : 'templates/master/material.html',
    });
  $locationProvider.html5Mode(true);
});

的.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]

的index.html

  <base href="http://localhost/test/">

1 个答案:

答案 0 :(得分:1)

找到答案。

希望这可以帮助他人。

更改.htaccess

RewriteEngine on
RewriteBase /test/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^ index.html [L]

更改头部的基本标签

<base href="/test/">