【问题标题】:how to refresh cookies in angularJS如何在angularJS中刷新cookie
【发布时间】:2019-04-03 06:18:20
【问题描述】:

我有一个 Angular Web 应用程序 在 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 我尝试刷新几次没有任何变化,最后我尝试在开发人员工具中禁用缓存并刷新它, 如何解决它,伙计们需要你的帮助。

【问题讨论】:

  • 当你禁用缓存时它修复了吗?
  • 是的,我禁用它并刷新浏览器,它会更改为我编写的最新代码

标签: javascript html angularjs session-cookies httpcookie


【解决方案1】:

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

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);

我不建议添加随机数

【讨论】:

  • 它仍然不起作用我仍然必须禁用和启用缓存刷新
  • 你试过随机数法吗?
猜你喜欢
  • 1970-01-01
  • 2016-11-18
  • 2016-07-17
  • 1970-01-01
  • 2019-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-24
相关资源
最近更新 更多