diff --git a/src/lib/config/nav-menu/all-nav-items.config.ts b/src/lib/config/nav-menu/all-nav-items.config.ts index 825e78fe..0c47f625 100644 --- a/src/lib/config/nav-menu/all-nav-items.config.ts +++ b/src/lib/config/nav-menu/all-nav-items.config.ts @@ -97,7 +97,7 @@ export const allNavItems: {[key: string]: NavMenuItem} = { }, blog: { label: 'Blog', - url: getMarketingUrl('/blog/all-posts'), + url: getMarketingUrl('/blog'), }, bookADemo: { label: 'Book a Demo', diff --git a/src/main.ts b/src/main.ts index 4141e8ac..332f4964 100644 --- a/src/main.ts +++ b/src/main.ts @@ -38,7 +38,7 @@ export type NavigationAppProps = { integrations?: {[key: string]: 'disable'} } -export type TcUniNavMethods = 'init' | 'update' | 'triggerFlow' +export type TcUniNavMethods = 'init' | 'update' | 'destroy' | 'triggerFlow' export type TcUniNavFn = ( method: TcUniNavMethods, @@ -54,6 +54,26 @@ const NavigationLoadersMap = { const instancesContextStore: { [key: string]: Map> } = {} +async function destroy( + targetId: string, +) { + if (Object.prototype.hasOwnProperty.call(instancesContextStore, targetId)) { + delete instancesContextStore[targetId]; + } + + if (typeof targetId !== 'string') { + throw new Error(`'targetId' should be a string`); + } + + const targetEl: Element | null = document.getElementById(targetId); + + if (targetEl?.nodeType !== Node.ELEMENT_NODE) { + throw new Error(`[TcUnivNav] 'target' must be a valid dom element with an id of #${targetId}!`); + } + + targetEl.innerHTML = ''; +} + /** * Initialize the navigation component * @param targetId Target element ID @@ -161,6 +181,10 @@ function execQueueCall(method: TcUniNavMethods, ...args: any[]) { triggerFlow.call(null, ...args) } + else if (method === 'destroy') { + destroy.call(null, ...args); + } + else if (method === 'trigger') { appPubSub.publish.call(appPubSub, ...args); } diff --git a/types/src/main.d.ts b/types/src/main.d.ts index dda39c0e..cf0a307f 100644 --- a/types/src/main.d.ts +++ b/types/src/main.d.ts @@ -21,5 +21,5 @@ export declare type NavigationAppProps = { [key: string]: 'disable'; }; }; -export declare type TcUniNavMethods = 'init' | 'update' | 'triggerFlow'; +export declare type TcUniNavMethods = 'init' | 'update' | 'destroy' | 'triggerFlow'; export declare type TcUniNavFn = (method: TcUniNavMethods, targetId: string, config: NavigationAppProps) => void;