From c5d80d96fbc84a34cb92d3f890b6d62e09267830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=BB=B6=E9=BE=99?= Date: Tue, 26 Dec 2023 19:56:42 +0800 Subject: [PATCH] fix: set default route (#354) --- src/router/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/router/index.ts b/src/router/index.ts index 60eebf24..2cfd6c9d 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -47,7 +47,23 @@ router.beforeEach((to, from, next) => { } if (to.path === "/") { - const defaultPath = (routesLayers[0] && routesLayers[0].children[0].path) || ""; + let defaultPath = ""; + for (const route of routesLayers) { + for (const child of route.children) { + if (child.meta.activate) { + defaultPath = child.path; + break; + } + } + if (defaultPath) { + break; + } + } + + if (!defaultPath) { + defaultPath = "/marketplace"; + } + next({ path: defaultPath }); } else { next();