目前,我的应用程序已部署,所有 js 都有时间戳版本。现在,当我再次构建我的 angular 应用程序时,js 将有一个新的时间戳版本。
有没有一种方法可以比较我的构建版本,如果不匹配,则允许用户从应用程序注销?
最佳答案
使用“@angular/service-worker”包的“SwUpdate”,您可以检查应用程序的当前版本和可用版本,并可以通过检查版本来执行您想要执行的操作。
例子:
import { SwUpdate } from '@angular/service-worker';
constructor(private swUpdate: SwUpdate) {}
//Here you can check the versions
this.swUpdate.available.subscribe((event) => {
console.log('current version: ', event.current);
console.log('available version: ', event.available);
if (confirm('Software update avaialble.')) {
this.swUpdate.activateUpdate().then(() => {
//Perform your action here
window.location.reload()
});
}
});
关于angular - 使用 Angular 10 部署后为客户端自动重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65576630/