fix: 修复 Hash 路由跳转丢失部署基路径
- 修复懒加载分包失败后跳转到站点根路径的问题 - 统一管理端和用户中心新窗口路由解析 - 增加部署基路径与 Hash 路由回归测试
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { createRouter, createWebHashHistory } from 'vue-router';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { resolveChunkReloadHref } from '../guard';
|
||||
|
||||
describe('chunk error reload', () => {
|
||||
it('preserves the deployment base and hash route', () => {
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory('/flow/'),
|
||||
routes: [
|
||||
{
|
||||
component: { template: '<div>workflow</div>' },
|
||||
path: '/ai/workflow',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const href = resolveChunkReloadHref(router, '/ai/workflow?source=sidebar');
|
||||
|
||||
expect(href).toBe('#/ai/workflow?source=sidebar');
|
||||
expect(new URL(href, 'https://easyflowtech.cn/flow/').href).toBe(
|
||||
'https://easyflowtech.cn/flow/#/ai/workflow?source=sidebar',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -71,6 +71,10 @@ function isDynamicImportChunkError(error: unknown) {
|
||||
);
|
||||
}
|
||||
|
||||
function resolveChunkReloadHref(router: Router, fullPath: string) {
|
||||
return router.resolve(fullPath).href;
|
||||
}
|
||||
|
||||
function setupChunkErrorGuard(router: Router) {
|
||||
router.onError((error, to) => {
|
||||
if (!isDynamicImportChunkError(error)) {
|
||||
@@ -94,7 +98,7 @@ function setupChunkErrorGuard(router: Router) {
|
||||
return;
|
||||
}
|
||||
sessionStorage.setItem(CHUNK_ERROR_RELOAD_KEY, fullPath);
|
||||
window.location.assign(fullPath);
|
||||
window.location.assign(resolveChunkReloadHref(router, fullPath));
|
||||
});
|
||||
|
||||
router.isReady().finally(() => {
|
||||
@@ -325,4 +329,4 @@ function createRouterGuard(router: Router) {
|
||||
setupChunkErrorGuard(router);
|
||||
}
|
||||
|
||||
export { createRouterGuard };
|
||||
export { createRouterGuard, resolveChunkReloadHref };
|
||||
|
||||
Reference in New Issue
Block a user