From f23632df3312d69dc78a19f458b3fef3114671f8 Mon Sep 17 00:00:00 2001 From: yangon <2689991790@qq.com> Date: Thu, 14 Nov 2024 16:36:38 +0800 Subject: [PATCH] fix:Solve the problem of URL automatically carrying slashes causing dead links (#1341) Remove the slash from the URL. ![image](https://github.com/user-attachments/assets/3fb2478e-47fa-48be-9796-9d766f443ea1) Co-authored-by: liyang --- src/theme/Navbar/Layout/index.tsx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/theme/Navbar/Layout/index.tsx b/src/theme/Navbar/Layout/index.tsx index 2e447e2e5bc8d..b9632cf47d140 100644 --- a/src/theme/Navbar/Layout/index.tsx +++ b/src/theme/Navbar/Layout/index.tsx @@ -5,10 +5,13 @@ import { useHideableNavbar, useNavbarMobileSidebar } from '@docusaurus/theme-com import { translate } from '@docusaurus/Translate'; import NavbarMobileSidebar from '@theme/Navbar/MobileSidebar'; import styles from './styles.module.css'; +import { useLocation } from '@docusaurus/router'; + function NavbarBackdrop(props) { return
; } export default function NavbarLayout({ children }) { + const location = useLocation(); const { navbar: { hideOnScroll, style }, } = useThemeConfig(); @@ -22,11 +25,12 @@ export default function NavbarLayout({ children }) { useEffect(() => { if (typeof window !== 'undefined') { const pathname = location.pathname.split('/')[1]; - const tempPath = ['get-starting', 'benchmark', 'ecosystems', 'faq', 'releasenotes'] - const isDocsPage = tempPath.includes(pathname) || tempPath.some(path => location.pathname.includes(`zh-CN/${path}`)) + const tempPath = ['get-starting', 'benchmark', 'ecosystems', 'faq', 'releasenotes']; + const isDocsPage = + tempPath.includes(pathname) || tempPath.some(path => location.pathname.includes(`zh-CN/${path}`)); const docsPage = pathname === 'docs' || location.pathname.includes('zh-CN/docs'); setIsDocsPage(docsPage); - setWithoutDoc(isDocsPage) + setWithoutDoc(isDocsPage); } if (typeof window !== 'undefined') { @@ -35,6 +39,17 @@ export default function NavbarLayout({ children }) { setIsCommunity(communityPage); } }, [typeof window !== 'undefined' && location.pathname]); + + useEffect(() => { + if ( + typeof window !== 'undefined' && + location.pathname.length > 1 && + location.pathname[location.pathname.length - 1] === '/' + ) { + window.location.pathname = location.pathname.slice(0, -1); + } + }, [location.pathname]); + return (