Skip to content

Commit

Permalink
Update Layout.js
Browse files Browse the repository at this point in the history
Signed-off-by: 赵璟 <[email protected]>
  • Loading branch information
zhaojing1987 authored Nov 12, 2024
1 parent b2058d9 commit 7e6d784
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions src/theme/Layout.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// src/theme/Layout.js
import { useLocation } from '@docusaurus/router';
import OriginalLayout from '@theme-original/Layout';
import React, { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
// // src/theme/Layout.js
// import { useLocation } from '@docusaurus/router';
// import OriginalLayout from '@theme-original/Layout';
// import React, { useEffect } from 'react';
// import { useHistory } from 'react-router-dom';

function useRemoveTrailingSlash() {
const location = useLocation();
const history = useHistory();
// function useRemoveTrailingSlash() {
// const location = useLocation();
// const history = useHistory();

useEffect(() => {
const { pathname, search, hash } = location;
if (pathname.length > 1 && pathname.endsWith('/')) {
const newPath = pathname.slice(0, -1) + search + hash;
console.log(`old pathname: ${pathname}, Redirecting to: ${newPath}`);
// 使用 history.replace 以避免页面刷新
history.replace(newPath);
}
}, [location, history]);
}
// useEffect(() => {
// const { pathname, search, hash } = location;
// if (pathname.length > 1 && pathname.endsWith('/')) {
// const newPath = pathname.slice(0, -1) + search + hash;
// console.log(`old pathname: ${pathname}, Redirecting to: ${newPath}`);
// // 使用 history.replace 以避免页面刷新
// history.replace(newPath);
// }
// }, [location, history]);
// }

export default function Layout(props) {
useRemoveTrailingSlash();
// export default function Layout(props) {
// useRemoveTrailingSlash();

return <OriginalLayout {...props} />;
}
// return <OriginalLayout {...props} />;
// }

//window.history.replaceState(null, '', newPath);
//window.location.replace(newPath);
// //window.history.replaceState(null, '', newPath);
// //window.location.replace(newPath);

0 comments on commit 7e6d784

Please sign in to comment.