diff --git a/src/theme/DocSidebar/Desktop/ProductSwitcher/VersionSwitcher.tsx b/src/theme/DocSidebar/Desktop/ProductSwitcher/VersionSwitcher.tsx index 799d91092..bf330b115 100644 --- a/src/theme/DocSidebar/Desktop/ProductSwitcher/VersionSwitcher.tsx +++ b/src/theme/DocSidebar/Desktop/ProductSwitcher/VersionSwitcher.tsx @@ -38,15 +38,22 @@ const VersionSwitcher = ({ isOpen, setIsOpen }) => { if (typeof window === "undefined") return null; if (!versions) return null; - if (!location.pathname.startsWith("/platform-enterprise/")) return null; + + if (!location.pathname.startsWith("/platform-enterprise")) return null; const items = versions.filter( - (version) => version.label !== currentVersion.label, + (version) => version.label !== currentVersion?.label, ); - // Extract the part of the URL after the current version - const currentVersionPrefix = `/platform-enterprise/${currentVersion.label}`; - const urlSuffix = location.pathname.replace(currentVersionPrefix, ""); + let urlSuffix = ""; + + if ( + currentVersion && + location.pathname.startsWith(`/platform-enterprise/${currentVersion.label}`) + ) { + const currentVersionPrefix = `/platform-enterprise/${currentVersion.label}`; + urlSuffix = location.pathname.replace(currentVersionPrefix, ""); + } return ( <> @@ -58,8 +65,10 @@ const VersionSwitcher = ({ isOpen, setIsOpen }) => { ref={dropdownRef} > - v{currentVersion.label}{" "} - {currentVersion.label == versions[0].label ? " (current)" : ""} + {currentVersion ? `v${currentVersion.label}` : "Version"}{" "} + {currentVersion && currentVersion.label === versions[0].label + ? " (current)" + : ""} {isOpen && (