From 3f4f2ea1f5df08c3a7f0acf005784281638a9345 Mon Sep 17 00:00:00 2001 From: loicduong Date: Sat, 7 Sep 2024 15:25:05 +0700 Subject: [PATCH] fix(core): fix breadcrumb when activeMenu is parent menu #25 --- src/store/modules/route/shared.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/store/modules/route/shared.ts b/src/store/modules/route/shared.ts index 9ddb732..86e6c99 100644 --- a/src/store/modules/route/shared.ts +++ b/src/store/modules/route/shared.ts @@ -281,11 +281,9 @@ export function getBreadcrumbsByRoute( const key = route.name as string const activeKey = route.meta?.activeMenu - const menuKey = activeKey || key - for (const menu of menus) { - if (menu.key === menuKey) { - const breadcrumbMenu = menuKey !== activeKey ? menu : getGlobalMenuByBaseRoute(route) + if (menu.key === key) { + const breadcrumbMenu = menu return [transformMenuToBreadcrumb(breadcrumbMenu)] } @@ -296,6 +294,19 @@ export function getBreadcrumbsByRoute( return [transformMenuToBreadcrumb(menu), ...result] } } + + if (menu.key === activeKey) { + const ROUTE_DEGREE_SPLITTER = '_' + + const parentKey = key.split(ROUTE_DEGREE_SPLITTER).slice(0, -1).join(ROUTE_DEGREE_SPLITTER) + + const breadcrumbMenu = getGlobalMenuByBaseRoute(route) + if (parentKey !== activeKey) { + return [transformMenuToBreadcrumb(breadcrumbMenu)] + } + + return [transformMenuToBreadcrumb(menu), transformMenuToBreadcrumb(breadcrumbMenu)] + } } return []