From 57b4a9d532b491803134d5a31eecb58adc40b7fb Mon Sep 17 00:00:00 2001 From: Soybean Date: Mon, 20 May 2024 00:28:16 +0800 Subject: [PATCH] fix(projects): add error handle when get routes in dynamic route mode. fixed 440 --- src/store/modules/route/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/store/modules/route/index.ts b/src/store/modules/route/index.ts index 4de30a36..1acaf69f 100644 --- a/src/store/modules/route/index.ts +++ b/src/store/modules/route/index.ts @@ -179,15 +179,18 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { async function initConstantRoute() { if (isInitConstantRoute.value) return; - if (authRouteMode.value === 'static') { - const staticRoute = createStaticRoutes(); + const staticRoute = createStaticRoutes(); + if (authRouteMode.value === 'static') { addConstantRoutes(staticRoute.constantRoutes); } else { const { data, error } = await fetchGetConstantRoutes(); if (!error) { addConstantRoutes(data); + } else { + // if fetch constant routes failed, use static constant routes + addConstantRoutes(staticRoute.constantRoutes); } } @@ -240,6 +243,9 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { handleUpdateRootRouteRedirect(home); setIsInitAuthRoute(true); + } else { + // if fetch user routes failed, reset store + authStore.resetStore(); } }