fix(router): avoid route preloading in development

This commit is contained in:
digua committed 2026-07-10 15:11:51 +08:00
1 parent dd40fc6502
commit be60b3ccfb
2 files changed
+9 -2

No files matched your search

+4 -2
View File
@@ -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)
}
+5
View File
@@ -1,5 +1,10 @@
import type { RouteRecordRaw } from 'vue-router'
/** 开发模式按需加载页面,避免失败的预加载请求污染后续动态路由导航。 */
export function shouldPreloadCriticalRoutes(isProduction: boolean): boolean {
return isProduction
}
export const appRoutes: RouteRecordRaw[] = [
{
path: '/login',