gpt4 book ai didi

javascript - 如何在angularJS中刷新cookie

转载 作者:行者123 更新时间:2023-12-03 00:50:35 25 4
gpt4 key购买 nike

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

最佳答案

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

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

我不建议添加随机数

关于javascript - 如何在angularJS中刷新cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53060371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com