mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-26 02:04:37 +08:00
fix(router): avoid route preloading in development
This commit is contained in:
1 parent
dd40fc6502
commit
be60b3ccfb
2 files changed
+9
-2
No files matched your search
+4
-2
@@ -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)
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
/** 开发模式按需加载页面,避免失败的预加载请求污染后续动态路由导航。 */
|
||||
export function shouldPreloadCriticalRoutes(isProduction: boolean): boolean {
|
||||
return isProduction
|
||||
}
|
||||
|
||||
export const appRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/login',
|
||||
|
||||
Reference in new issue
Block a user