diff --git a/client/components/NavBar.jsx b/client/components/NavBar.jsx index c7b16af..d43ccbd 100644 --- a/client/components/NavBar.jsx +++ b/client/components/NavBar.jsx @@ -146,6 +146,16 @@ const ColorModeButton = () => { const LocaleSelect = ({ mr }) => { const { formatMessage } = useIntl(); + const { pathname, query } = useRouter(); + + let currentPath = pathname; + if (query?.id) { + currentPath = `/chat/${query.id}`; + } else if (query?.iscommunity) { + currentPath = `?iscommunity=${query.iscommunity}`; + } else if (query?.q) { + currentPath = `?q=${query.q}`; + } return ( <Menu> @@ -163,10 +173,10 @@ const LocaleSelect = ({ mr }) => { /> </Tooltip> <MenuList size="sm"> - <NextLink href="/" locale="en"> + <NextLink href={currentPath} locale="en"> <MenuItem>English</MenuItem> </NextLink> - <NextLink href="/" locale="fr"> + <NextLink href={currentPath} locale="fr"> <MenuItem>French</MenuItem> </NextLink> </MenuList> diff --git a/client/pages/index.jsx b/client/pages/index.jsx index de3abb3..a368c85 100644 --- a/client/pages/index.jsx +++ b/client/pages/index.jsx @@ -36,8 +36,6 @@ export default function Home() { const { isOpen, onOpen, onClose } = useDisclosure(); const { formatMessage } = useIntl(); const { - locale, - defaultLocale, push, query: { q, iscommunity }, } = useRouter(); @@ -113,11 +111,7 @@ export default function Home() { const handleSearch = async (e) => { e.preventDefault(); setCurrentPage(0); - push( - `${locale !== defaultLocale ? locale : ""}/?q=${curSearchQuery}`, - undefined, - { shallow: true } - ); + push(`/?q=${curSearchQuery}`, undefined, { shallow: true }); }; const displayMorePages = async () => { @@ -155,17 +149,13 @@ export default function Home() { const handleCommunityChange = (newIsCommunity) => { setCurrentPage(0); if (newIsCommunity === 0) { - push(`${locale !== defaultLocale ? locale : ""}/`, undefined, { + push(`/`, undefined, { shallow: true, }); } else { - push( - `${locale !== defaultLocale ? locale : ""}/?iscommunity=${ - newIsCommunity === 2 - }`, - undefined, - { shallow: true } - ); + push(`/?iscommunity=${newIsCommunity === 2}`, undefined, { + shallow: true, + }); } setSearchQuery(""); };