11'use client' ;
22
33import Select from '@node-core/ui-components/Common/Select' ;
4- import { useTranslations } from 'next-intl' ;
4+ import { useLocale , useTranslations } from 'next-intl' ;
55import type { FC } from 'react' ;
66import { useContext } from 'react' ;
77
8+ import { redirect , usePathname } from '#site/navigation' ;
89import {
910 ReleaseContext ,
1011 ReleasesContext ,
@@ -26,6 +27,28 @@ const VersionDropdown: FC = () => {
2627 const { releases } = useContext ( ReleasesContext ) ;
2728 const { release, setVersion } = useContext ( ReleaseContext ) ;
2829 const t = useTranslations ( ) ;
30+ const locale = useLocale ( ) ;
31+ const pathname = usePathname ( ) ;
32+
33+ // Allows us to keep the route semantically correct to what the user should expect
34+ // from the /current and non /current routes.
35+ const setVersionOrNavigate = ( version : string ) => {
36+ const release = releases . find (
37+ ( { versionWithPrefix } ) => versionWithPrefix === version
38+ ) ;
39+
40+ if ( release ?. status === 'LTS' && pathname . includes ( 'current' ) ) {
41+ redirect ( { href : '/download' , locale } ) ;
42+ return ;
43+ }
44+
45+ if ( release ?. status === 'Current' && ! pathname . includes ( 'current' ) ) {
46+ redirect ( { href : '/download/current' , locale } ) ;
47+ return ;
48+ }
49+
50+ setVersion ( version ) ;
51+ } ;
2952
3053 return (
3154 < Select
@@ -35,7 +58,7 @@ const VersionDropdown: FC = () => {
3558 label : getDropDownStatus ( versionWithPrefix , status ) ,
3659 } ) ) }
3760 defaultValue = { release . versionWithPrefix }
38- onChange = { setVersion }
61+ onChange = { setVersionOrNavigate }
3962 className = "min-w-36"
4063 inline = { true }
4164 />
0 commit comments