From f6863c3f25fc5a519d35d04cb2710ff6d366ab27 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Wed, 3 Apr 2024 18:12:11 -0700 Subject: [PATCH] Fix version selector not working and preserve route when changing versions --- docs/site/components/Navigation.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/site/components/Navigation.tsx b/docs/site/components/Navigation.tsx index ce0dd465c..184b72123 100644 --- a/docs/site/components/Navigation.tsx +++ b/docs/site/components/Navigation.tsx @@ -216,7 +216,21 @@ export const VersionSelector = () => { }} value={router.basePath || 'latest'} onChange={(e) => { - router.push(`${DOCS_BASE_URL}/${e.target.value}`); + const currentRoute = router.pathname + .split('/') + .filter((s) => { + // filter out empty string and url elements that include the version + if ( + s && + !['latest', 'next', ...released.map((r) => r.path)].includes(s) + ) { + return true; + } + + return false; + }) + .join('/'); + router.push(`${DOCS_BASE_URL}${e.target.value}/${currentRoute}`); }} >