File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -169,6 +169,12 @@ export default function TopNav({
169169 const [ isScrolled , setIsScrolled ] = useState ( false ) ;
170170 const scrollParentRef = useRef < HTMLDivElement > ( null ) ;
171171 const { asPath} = useRouter ( ) ;
172+ const translationsHref =
173+ section === 'learn' || section === 'reference'
174+ ? `/community/translations?from=${ encodeURIComponent (
175+ asPath . split ( / [ ? # ] / ) [ 0 ]
176+ ) } `
177+ : '/community/translations' ;
172178
173179 // HACK. Fix up the data structures instead.
174180 if ( ( routeTree as any ) . routes . length === 1 ) {
@@ -378,7 +384,7 @@ export default function TopNav({
378384 </ div >
379385 < div className = "flex" >
380386 < Link
381- href = "/community/translations"
387+ href = { translationsHref }
382388 aria-label = "Translations"
383389 className = "active:scale-95 transition-transform flex w-12 h-12 rounded-full items-center justify-center hover:bg-primary/5 hover:dark:bg-primary-dark/5 outline-link" >
384390 { languageIcon }
Original file line number Diff line number Diff line change 1212import { Children , useContext , useMemo } from 'react' ;
1313import * as React from 'react' ;
1414import cn from 'classnames' ;
15+ import { useRouter } from 'next/router' ;
1516import type { HTMLAttributes } from 'react' ;
1617
1718import CodeBlock from './CodeBlock' ;
@@ -469,6 +470,9 @@ function InlineTocItem({items}: {items: Array<NestedTocNode>}) {
469470type TranslationProgress = 'complete' | 'in-progress' ;
470471
471472function LanguageList ( { progress} : { progress : TranslationProgress } ) {
473+ const from = useRouter ( ) . query . from ;
474+ const pathname =
475+ typeof from === 'string' && / ^ \/ (? ! \/ ) [ ^ \\ ? # ] * $ / . test ( from ) ? from : '' ;
472476 const allLanguages = React . useContext ( LanguagesContext ) ?? [ ] ;
473477 const languages = allLanguages
474478 . filter (
@@ -484,7 +488,10 @@ function LanguageList({progress}: {progress: TranslationProgress}) {
484488 { languages . map ( ( { code, name, enName} ) => {
485489 return (
486490 < LI key = { code } >
487- < Link href = { `https://${ code } .react.dev/` } >
491+ < Link
492+ href = { `https://${ code } .react.dev${
493+ progress === 'complete' ? pathname || '/' : '/'
494+ } `} >
488495 { enName } ({ name } )
489496 </ Link > { ' ' }
490497 —{ ' ' }
You can’t perform that action at this time.
0 commit comments