From e63e2152d6f25d30f62d08989737b91887e35efa Mon Sep 17 00:00:00 2001 From: XiaoFans <57002549+6get-xiaofan@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:55:10 +0800 Subject: [PATCH 1/2] Fix: Ensure route.children existence before accessing in initRouter() In the initRouter() function, added a check to ensure the existence of route.children before accessing it. This prevents the "TypeError: Cannot read properties of undefined" error that occurred when trying to access route.children[0] without confirming its existence. The check ensures that route.children is present and not an empty array before proceeding to access its elements. --- src/router/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/router/index.ts b/src/router/index.ts index 8565cd2..9df7082 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -158,7 +158,12 @@ router.beforeEach((to: ToRouteType, _from, next) => { getTopMenu(true); // query、params模式路由传参数的标签页不在此处处理 if (route && route.meta?.title) { - if (isAllEmpty(route.parentId) && route.meta?.backstage) { + if ( + isAllEmpty(route.parentId) && + route.meta?.backstage && + route.children && + route.children.length > 0 + ) { // 此处为动态顶级路由(目录) const { path, name, meta } = route.children[0]; useMultiTagsStoreHook().handleTags("push", { From 04875659ae8b08a7330613c8b99e2d23139c4418 Mon Sep 17 00:00:00 2001 From: XiaoFans <57002549+6get-xiaofan@users.noreply.github.com> Date: Mon, 19 Feb 2024 00:53:12 +0800 Subject: [PATCH 2/2] Fix serverConfig.json fetching behavior across nested routes Ensure that serverConfig.json is fetched consistently from the root directory regardless of the nested route level. Adjusted the axios request to use an absolute path, specifically targeting the serverConfig.json file in the root directory. This resolves the issue where serverConfig.json was being requested relative to the current route, leading to inconsistencies when navigating across nested routes. --- src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/index.ts b/src/config/index.ts index 4cd3016..1395088 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -31,7 +31,7 @@ export const getServerConfig = async (app: App): Promise => { app.config.globalProperties.$config = getConfig(); return axios({ method: "get", - url: `${VITE_PUBLIC_PATH}serverConfig.json` + url: `${window.location.origin}/serverConfig.json` }) .then(({ data: config }) => { let $config = app.config.globalProperties.$config;