Javascript 如何在angularJS中刷新Cookie

Javascript 如何在angularJS中刷新Cookie,javascript,html,angularjs,session-cookies,httpcookie,Javascript,Html,Angularjs,Session Cookies,Httpcookie,我有一个角度的网页应用程序 在index.html中,代码编写 app.run(function ($rootScope, $cookieStore, $location, $window) { $rootScope.$on("$routeChangeStart", function (event, next, current) { if ($cookieStore.get('username') == null) { $window.location.href = '/

我有一个角度的网页应用程序 在index.html中,代码编写

app.run(function ($rootScope, $cookieStore, $location, $window) {
$rootScope.$on("$routeChangeStart", function (event, next, current) {
    if ($cookieStore.get('username') == null) {
        $window.location.href = '/report/login.html';
    } else {
    }

});
}))

使用上面的代码,我尝试将其更改为/regist/index.html,并且已保存更改, 但是当我尝试访问它时,网页仍然指向旧位置而不是最新的location href我尝试刷新几次,没有任何更改,最后我尝试禁用开发人员工具中的缓存并刷新它,
如何修复需要您的帮助。

您可以维护应用程序的版本索引,然后将该版本添加为URL后缀

var appVersion = '1.0';

app.run(function ($rootScope, $cookieStore, $location, $window) {
 $rootScope.$on("$routeChangeStart", function (event, next, current) {
    if ($cookieStore.get('username') == null) {
        $window.location.href = '/report/login.html?v=' + appVersion;
    } else {
    }

 });
});
或随机数作为url后缀

 $window.location.href = '/report/login.html?v=' +  Math.floor(Math.random() * 1000);

我不建议您在解除禁用缓存时添加随机数

它是否已修复?是的,我已禁用并刷新浏览器它更改为最新代码我编写了它仍然无法工作我仍必须禁用并启用缓存刷新你尝试过随机数方法吗?