diff --git a/src/segments/Footer.tsx b/src/segments/Footer.tsx index b04013566c..7b045fcc49 100644 --- a/src/segments/Footer.tsx +++ b/src/segments/Footer.tsx @@ -10,6 +10,7 @@ import { useLocation } from '@docusaurus/router'; import { useTranslation } from 'react-i18next'; import { BsTwitterX } from 'react-icons/bs'; import styled from 'styled-components'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; // Internal Components import { @@ -38,6 +39,8 @@ function Footer() { const { t } = useTranslation(); const isMobile = useMediaQuery(device.mobileL); const isTablet = useMediaQuery(device.tablet); + const { siteConfig } = useDocusaurusContext(); + const baseURL = siteConfig?.baseUrl.slice(0, -1) || ''; // for navigation const history = useHistory(); @@ -57,7 +60,7 @@ function Footer() { if (href.includes('http')) { window.location.href = href; } else { - history.push(href); + history.push(baseURL + href); } scrollToTop(); } @@ -66,20 +69,20 @@ function Footer() { if (href.includes('http')) { window.open(href, target); } else { - window.open(`${window.location.origin}${href}`, target); + window.open(`${window.location.origin}${baseURL + href}`, target); } // scrollToTop(); } } else if (id) { - if (location?.pathname !== '/' && id) { - history.push('/'); + if (location?.pathname !== baseURL + '/' && id) { + history.push(baseURL + '/'); setTimeout(() => { - document.getElementById(id).scrollIntoView({ behavior: 'smooth' }); - }, 1500); + document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' }); + }, 300); } - if (location?.pathname === '/') { - document.getElementById(id).scrollIntoView({ behavior: 'smooth' }); + if (location?.pathname === baseURL + '/') { + document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' }); } } else return; }; diff --git a/src/segments/Header.tsx b/src/segments/Header.tsx index bf12bda8e7..f248f1e1af 100644 --- a/src/segments/Header.tsx +++ b/src/segments/Header.tsx @@ -30,7 +30,6 @@ import { Span, } from '@site/src/css/SharedStyling'; import useMediaQuery from '@site/src/hooks/useMediaQuery'; -import { getPublicAssetPath } from '../utils/useRouteHelper'; // Import Assets import { AiOutlineClose } from 'react-icons/ai'; @@ -70,7 +69,7 @@ function Header() { const [scrollDirection, setScrollDirection] = useState(null); const location = useLocation(); const { siteConfig } = useDocusaurusContext(); - const baseUrl = siteConfig?.baseUrl.slice(0, -1); + const baseURL = siteConfig?.baseUrl.slice(0, -1) || ''; // const [isAlertVisible, setIsAlertVisible] = useState(true); // for navigation @@ -161,7 +160,7 @@ function Header() { if (href.includes('http')) { window.location.href = href; } else { - history.push(baseUrl + href); + history.push(baseURL + href); } } } else { @@ -169,67 +168,25 @@ function Header() { if (href.includes('http')) { window.open(href, target); } else { - window.open(`${window.location.origin}${baseUrl + href}`, target); + window.open(`${window.location.origin}${baseURL + href}`, target); } } } else if (id) { if (showMobileMenu) toggleMobileMenu(); - if (location?.pathname !== '/' && id) { - // history.push('/'); + if (location?.pathname !== baseURL + '/' && id) { + history.push(baseURL + '/'); setTimeout(() => { document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' }); - }, 500); + }, 200); } - if (location?.pathname === '/') { + if (location?.pathname === baseURL + '/') { document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' }); } } else return; }; - // const HeaderSpace = ({ item, index }) => { - // const openLink = async (e, href, id, target) => { - // e.stopPropagation(); - - // if (href) { - // if (target && target !== '_blank') { - // if (target === '_self') { - // // check if url is external - // if (href.includes('http')) { - // window.location.href = href; - // } else { - // history.push(href); - // } - // } - // } else { - // // check if url is internal and if so append the base url - // if (href.includes('http')) { - // window.open(href, target); - // } else { - // window.open(`${window.location.origin}${href}`, target); - // } - // } - // } else if (id) { - // if (showMobileMenu) toggleMobileMenu(); - - // // gsap.to(window, { - // // duration: 0.75, - // // scrollTo: { y: `#${id}` }, - // // }); - // if (location.pathname !== '/' && id) { - // history.push('/'); - // setTimeout(() => { - // document.getElementById(id).scrollIntoView({ behavior: 'smooth' }); - // }, 1500); - // } - - // if (location.pathname === '/') { - // document.getElementById(id).scrollIntoView({ behavior: 'smooth' }); - // } - // } else return; - // }; - return ( openLink(e, item.href, item.id, item.target)}> {item.srcrefoff && ( diff --git a/src/theme/Navbar/Content/index.js b/src/theme/Navbar/Content/index.js index 33f8ffcd44..6c14692908 100644 --- a/src/theme/Navbar/Content/index.js +++ b/src/theme/Navbar/Content/index.js @@ -36,6 +36,7 @@ import styled from 'styled-components'; import { HeaderList } from '../../../config/HeaderList'; import styles from './styles.module.css'; import useBaseUrl from '@docusaurus/useBaseUrl'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; const defaultMobileMenuState = { 0: false, @@ -84,10 +85,15 @@ export default function NavbarContent() { const history = useHistory(); const location = useLocation(); const pathname = location?.pathname; + const { siteConfig } = useDocusaurusContext(); + const baseURL = siteConfig?.baseUrl.slice(0, -1) || ''; const mobileSidebar = useNavbarMobileSidebar(); const items = useNavbarItems(); - const [rightItems] = splitNavbarItems(items); + + // eslint has to disabled for this line cause the leftItems is required + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const [leftItems, rightItems] = splitNavbarItems(items); const searchBarItem = items.find((item) => item.type === 'search'); const isLaptopM = useMediaQuery(device.laptopM); @@ -126,7 +132,7 @@ export default function NavbarContent() { if (href.includes('http')) { window.location.href = href; } else { - history.push(href); + history.push(baseURL + href); } } } else { @@ -134,7 +140,7 @@ export default function NavbarContent() { if (href.includes('http')) { window.open(href, target); } else { - window.open(`${window.location.origin}${href}`, target); + window.open(`${window.location.origin}${baseURL + href}`, target); } } } else if (id) { @@ -225,7 +231,7 @@ export default function NavbarContent() { {/* Change Header from docs to blog if required */} {!isLaptopM && - (pathname.startsWith('/docs') ? ( + (pathname.startsWith(baseURL + '/docs') ? ( Docs diff --git a/src/theme/NotFound/Content/index.tsx b/src/theme/NotFound/Content/index.tsx index b1e4918c7a..39e594695b 100644 --- a/src/theme/NotFound/Content/index.tsx +++ b/src/theme/NotFound/Content/index.tsx @@ -16,12 +16,15 @@ import styled from 'styled-components'; // Internal Components import Footer from '../../../segments/Footer'; +import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; export default function NotFoundContent({ className }: Props): JSX.Element { const location = useLocation(); + const { siteConfig } = useDocusaurusContext(); + const baseURL = siteConfig?.baseUrl.slice(0, -1); // Determine if the pathname starts with '/docs' - const isDocsPage = location?.pathname.startsWith('/docs'); + const isDocsPage = location?.pathname.startsWith(baseURL + '/docs'); return ( @@ -61,7 +64,6 @@ export default function NotFoundContent({ className }: Props): JSX.Element { - {isDocsPage &&