项目中因为用到了angularjs做路由跳转机制,然后每次加载不同的路由页面的时候,它总是使用缓存,重新加载页面都没用。强制刷新也没用,搞得头昏脑胀,不过最后也算是爬坑了!!
来来来,爬坑来了:在你的模板页面后面加个时间参数页面就会每次都重新加载
when('/data', {
templateUrl: 'partial/customer_ask.html?t=' + Math.floor(Date.now() / 1000),
controller: 'dataController'
}).
或者在配置路由之后
config.run(function($rootScope, $templateCache) {
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (typeof(current) !== 'undefined'){
$templateCache.remove(current.templateUrl);
}
});
})
究极方法
config.config(['$routeProvider','$httpProvider', function ($routeProvider, $httpProvider) {
$routeProvider
//上面路由模板不管
if (!$httpProvider.defaults.headers.get) {
$httpProvider.defaults.headers.get = {};
}
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
}]);