Skip to content

Commit

Permalink
fix:Solve the problem of URL automatically carrying slashes causing d…
Browse files Browse the repository at this point in the history
…ead links (#1341)

Remove the slash from the URL.

![image](https://github.com/user-attachments/assets/3fb2478e-47fa-48be-9796-9d766f443ea1)

Co-authored-by: liyang <[email protected]>
  • Loading branch information
yang1666204 and liyang authored Nov 14, 2024
1 parent b4f695b commit f23632d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/theme/Navbar/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <div role="presentation" {...props} className={clsx('navbar-sidebar__backdrop', props.className)} />;
}
export default function NavbarLayout({ children }) {
const location = useLocation();
const {
navbar: { hideOnScroll, style },
} = useThemeConfig();
Expand All @@ -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') {
Expand All @@ -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 (
<nav
ref={navbarRef}
Expand Down

0 comments on commit f23632d

Please sign in to comment.