Skip to content

Commit 7d89cd8

Browse files
committed
fix: version switcher 404 on non versioned pages
1 parent 66f3409 commit 7d89cd8

2 files changed

Lines changed: 4 additions & 56 deletions

File tree

src/components/patterns/Sidebar/SidebarVersionManager.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@ export class SidebarVersionManager {
1010
}
1111

1212
setup(): void {
13-
const versionSwitchers = this.sidebar.querySelectorAll(
14-
'[data-version-switcher] select, [data-version-select]'
15-
);
13+
const versionSwitchers = this.sidebar.querySelectorAll('[data-version-switcher]');
1614

1715
versionSwitchers.forEach((switcher) => {
18-
switcher.addEventListener('change', (e) => {
19-
const select = e.target as HTMLSelectElement;
20-
this.handleVersionChange(select.value);
21-
});
16+
switcher.addEventListener('select-change', ((e: CustomEvent<{ value: string }>) => {
17+
this.handleVersionChange(e.detail.value);
18+
}) as EventListener);
2219
});
2320
}
2421

@@ -129,17 +126,4 @@ export class SidebarVersionManager {
129126
updatePath(path: string[]): void {
130127
this.activeSubmenuPath = path;
131128
}
132-
133-
getVersion(): string {
134-
return this.currentVersion;
135-
}
136-
137-
setVersion(version: string): void {
138-
const versionSelects =
139-
this.sidebar.querySelectorAll<HTMLSelectElement>('[data-version-select]');
140-
versionSelects.forEach((select) => {
141-
select.value = version;
142-
});
143-
this.handleVersionChange(version);
144-
}
145129
}

src/components/patterns/VersionSwitcher/VersionSwitcher.astro

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,6 @@ const selectOptions: SelectOption[] = versions.map((version) => ({
7272
size="md"
7373
variant="default"
7474
fullWidth
75-
data-version-select
7675
aria-label={t('version.selectLabel')}
7776
/>
7877
</Flex>
79-
80-
<script>
81-
function handleVersionChange(event: Event) {
82-
const customEvent = event as CustomEvent<{ value: string }>;
83-
const newVersion = customEvent.detail.value;
84-
const currentPath = window.location.pathname;
85-
86-
const pathParts = currentPath.split('/').filter(Boolean);
87-
88-
const versionIndex = pathParts.findIndex((part) => /^\d+x$/.test(part));
89-
90-
if (versionIndex !== -1) {
91-
pathParts[versionIndex] = newVersion;
92-
} else if (pathParts.length >= 2) {
93-
pathParts.splice(1, 0, newVersion);
94-
}
95-
96-
window.location.href = '/' + pathParts.join('/');
97-
}
98-
99-
function initVersionSwitcher() {
100-
const versionSwitchers = document.querySelectorAll('[data-version-switcher]');
101-
102-
versionSwitchers.forEach((versionSwitcher) => {
103-
const selectContainer = versionSwitcher.querySelector('[data-select-container]');
104-
if (!selectContainer) return;
105-
106-
selectContainer.removeEventListener('select-change', handleVersionChange);
107-
selectContainer.addEventListener('select-change', handleVersionChange);
108-
});
109-
}
110-
111-
initVersionSwitcher();
112-
document.addEventListener('astro:page-load', initVersionSwitcher);
113-
</script>

0 commit comments

Comments
 (0)