From be60b3ccfbdbca5c13a01c20ff97baf9a8a9228c Mon Sep 17 00:00:00 2001 From: digua Date: Fri, 10 Jul 2026 11:34:12 +0800 Subject: [PATCH] fix(router): avoid route preloading in development --- src/routes/index.ts | 6 ++++-- src/routes/routes.ts | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/routes/index.ts b/src/routes/index.ts index 02dbf08a..1f6c89fe 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,7 +1,7 @@ import { createRouter, createWebHashHistory } from 'vue-router' import { IS_ELECTRON } from '@/utils/platform' import { useAuthStore } from '@/stores/auth' -import { appRoutes } from './routes' +import { appRoutes, shouldPreloadCriticalRoutes } from './routes' export const router = createRouter({ routes: appRoutes, @@ -39,4 +39,6 @@ function preloadCriticalRoutes() { }) } -router.isReady().then(preloadCriticalRoutes) +if (shouldPreloadCriticalRoutes(import.meta.env.PROD)) { + router.isReady().then(preloadCriticalRoutes) +} diff --git a/src/routes/routes.ts b/src/routes/routes.ts index 6316ca30..808d7dde 100644 --- a/src/routes/routes.ts +++ b/src/routes/routes.ts @@ -1,5 +1,10 @@ import type { RouteRecordRaw } from 'vue-router' +/** 开发模式按需加载页面,避免失败的预加载请求污染后续动态路由导航。 */ +export function shouldPreloadCriticalRoutes(isProduction: boolean): boolean { + return isProduction +} + export const appRoutes: RouteRecordRaw[] = [ { path: '/login',