fix(admin): 发版 chunk 自动刷新、nginx 缓存策略与审计页 i18n
lazy route 加载失败时刷新入口;index.html 不缓存;补全 audit.col.operator/ip 等拆包遗漏 key。
This commit is contained in:
@@ -250,4 +250,28 @@ router.beforeEach(async (to) => {
|
||||
return true;
|
||||
});
|
||||
|
||||
/** 发版后旧 index.html 可能引用已不存在的 hash chunk,自动刷新一次拉最新入口。 */
|
||||
function isLazyChunkLoadError(err: unknown): boolean {
|
||||
const msg = err instanceof Error ? err.message : String(err ?? '');
|
||||
return (
|
||||
msg.includes('Failed to fetch dynamically imported module') ||
|
||||
msg.includes('Importing a module script failed') ||
|
||||
msg.includes('error loading dynamically imported module')
|
||||
);
|
||||
}
|
||||
|
||||
const CHUNK_RELOAD_FLAG = 'admin:chunk-reload';
|
||||
|
||||
router.onError((error, to) => {
|
||||
if (!isLazyChunkLoadError(error)) throw error;
|
||||
const target = to.fullPath || '/';
|
||||
if (!sessionStorage.getItem(CHUNK_RELOAD_FLAG)) {
|
||||
sessionStorage.setItem(CHUNK_RELOAD_FLAG, target);
|
||||
window.location.assign(target);
|
||||
return;
|
||||
}
|
||||
sessionStorage.removeItem(CHUNK_RELOAD_FLAG);
|
||||
throw error;
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user