diff --git a/libs/blocks/global-navigation/global-navigation.js b/libs/blocks/global-navigation/global-navigation.js index 3e2fc1777c..fa9aab0763 100644 --- a/libs/blocks/global-navigation/global-navigation.js +++ b/libs/blocks/global-navigation/global-navigation.js @@ -5,6 +5,7 @@ import { loadIms, decorateLinks, loadScript, + getGnavSource, } from '../../utils/utils.js'; import { closeAllDropdowns, @@ -1174,19 +1175,9 @@ class Gnav { }; } -const getSource = async () => { - const { locale, dynamicNavKey } = getConfig(); - let url = getMetadata('gnav-source') || `${locale.contentRoot}/gnav`; - if (dynamicNavKey) { - const { default: dynamicNav } = await import('../../features/dynamic-navigation/dynamic-navigation.js'); - url = dynamicNav(url, dynamicNavKey); - } - return url; -}; - export default async function init(block) { const { mep } = getConfig(); - const sourceUrl = await getSource(); + const sourceUrl = await getGnavSource(); const newMobileNav = getMetadata('mobile-gnav-v2') !== 'false'; const [url, hash = ''] = sourceUrl.split('#'); if (hash === '_noActiveItem') { diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 0fad978a00..c449d0baba 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -751,6 +751,16 @@ function decorateDefaults(el) { }); } +export async function getGnavSource() { + const { locale, dynamicNavKey } = getConfig(); + let url = getMetadata('gnav-source') || `${locale.contentRoot}/gnav`; + if (dynamicNavKey) { + const { default: dynamicNav } = await import('../features/dynamic-navigation/dynamic-navigation.js'); + url = dynamicNav(url, dynamicNavKey); + } + return url; +}; + function decorateHeader() { const breadcrumbs = document.querySelector('.breadcrumbs'); breadcrumbs?.remove(); @@ -772,9 +782,8 @@ function decorateHeader() { const dynamicNavActive = getMetadata('dynamic-nav') === 'on' && window.sessionStorage.getItem('gnavSource') !== null; if (!dynamicNavActive && (baseBreadcrumbs || breadcrumbs || autoBreadcrumbs)) header.classList.add('has-breadcrumbs'); - const gnavSource = getMetadata('gnav-source'); - const gnavUrl = gnavSource.split('/'); - const gnavName = gnavUrl[gnavUrl.length - 1]; + const gnavSource = getGnavSource(); + const gnavName = gnavSource.split('/').pop(); if (gnavName.match('localnav') && getMetadata('mobile-gnav-v2') !== 'false') { // Preserving space to avoid CLS issue