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',