From 206b4a5ee0e2f20856407c9b73e3bd03de0d5427 Mon Sep 17 00:00:00 2001 From: heyanlong Date: Tue, 26 Dec 2023 17:26:41 +0800 Subject: [PATCH 1/3] feat: default route --- 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 60eebf24e..3bcc0e5d4 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(); From eda486b522b639397d9b9bb02a638ade732289d1 Mon Sep 17 00:00:00 2001 From: Fine0830 Date: Tue, 26 Dec 2023 19:44:35 +0800 Subject: [PATCH 2/3] Update src/router/index.ts --- src/router/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.ts b/src/router/index.ts index 3bcc0e5d4..7d10819e9 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -55,7 +55,7 @@ router.beforeEach((to, from, next) => { break; } } - if (defaultPath !== "") { + if (defaultPath) { break; } } From 87e5c2bba0316824cfdf421a187003a73a150b5c Mon Sep 17 00:00:00 2001 From: Fine0830 Date: Tue, 26 Dec 2023 19:44:42 +0800 Subject: [PATCH 3/3] Update src/router/index.ts --- src/router/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/index.ts b/src/router/index.ts index 7d10819e9..2cfd6c9d1 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -60,7 +60,7 @@ router.beforeEach((to, from, next) => { } } - if (defaultPath === "") { + if (!defaultPath) { defaultPath = "/marketplace"; }