From c3825e3e9dac22dbe937bc421d8e11c3b3f07e23 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Sat, 17 Aug 2019 19:11:31 -0400 Subject: [PATCH] Stay on the same page when switching languages --- src/components/LayoutHeader/Header.js | 4 +- src/pages/languages.js | 89 +++++++++++++++------------ 2 files changed, 51 insertions(+), 42 deletions(-) diff --git a/src/components/LayoutHeader/Header.js b/src/components/LayoutHeader/Header.js index e0a285e84ff..45a8cd76ad0 100644 --- a/src/components/LayoutHeader/Header.js +++ b/src/components/LayoutHeader/Header.js @@ -199,7 +199,9 @@ const Header = ({location}: {location: Location}) => ( borderRadius: 15, }, }} - to="/languages"> + to={`/languages#!${location.pathname + + location.search + + location.hash}`}> {' '} ( - - -
-
-
Languages
- - -
-

- The React documentation is available in the following languages: -

- - - -

In Progress

- - -

Needs Contributors

- - -

- Don't see your language above?{' '} - - Let us know - - . -

+const Languages = ({location}: Props) => { + console.log('#', location.hash); + const pathname = location.hash.startsWith('#!/') + ? location.hash.slice(2) + : '/'; + return ( + + +
+
+
Languages
+ + +
+

+ The React documentation is available in the following languages: +

+ + + +

In Progress

+ + +

Needs Contributors

+ + +

+ Don't see your language above?{' '} + + Let us know + + . +

+
-
- - -); + + + ); +}; -const LanguagesGrid = ({languages}) => ( +const LanguagesGrid = ({languages, pathname}) => (
    ( key={code} code={code} name={name} + pathname={pathname} status={status} translatedName={translated_name} /> @@ -104,7 +111,7 @@ const LanguagesGrid = ({languages}) => (
); -const Language = ({code, name, status, translatedName}) => { +const Language = ({code, name, pathname, status, translatedName}) => { const prefix = code === 'en' ? '' : `${code}.`; return ( @@ -141,7 +148,7 @@ const Language = ({code, name, status, translatedName}) => { {status === 0 && translatedName} {status > 0 && (