Skip to content

Commit

Permalink
setup gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dxu104 committed Apr 28, 2024
1 parent b708dc1 commit f0cbaef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function App() {
function handlePageChange() {
// 使用 window.location.hash 获取哈希值作为页面
const path = window.location.hash.slice(1); // 移除前面的 '#'
// window.location.hash = path;

setPage(path || "/about"); // 如果没有哈希,则默认为 "/about"
}
handlePageChange(); // 设置初始页面
Expand Down
4 changes: 2 additions & 2 deletions src/jsx/FooterLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const footerLink = [
},
{
name: "Contact Me",
path: "ContactMe",
path: "contactme",
},
];

Expand All @@ -17,7 +17,7 @@ function FooterLink({ setPage }) {
<div key={item.name} className="footer-link">
<a href={`#${item.path}`} onClick={(e) => {
e.preventDefault(); // 阻止链接的默认行为
window.location.hash = item.path; // 更新哈希部分
// window.location.hash = item.path; // 更新哈希部分
setPage('/' + item.path); // 更新页面状态
}}>
{item.name}
Expand Down
38 changes: 16 additions & 22 deletions src/jsx/MainArea.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
// import { useState } from 'react';
import { useEffect } from 'react';
import AboutMe from './AboutMe';
import Experience from './Experience';
import Projects from './Projects';
import Resume from './Resume';
import { useEffect } from 'react';

import Privacy from './Privacy';
import ContactMe from './ContactMe';

function MainArea({ page, setPage }) {
useEffect(() => {
function handlePageChange() {
const path = window.location.hash.slice(1) || '/about'; // 获取哈希值,并提供默认页面
const path = window.location.hash.slice(1) || '/about';
console.log("Setting page to:", path);
setPage(path);
}


window.addEventListener("hashchange", handlePageChange); // 监听 hashchange 事件
handlePageChange(); // 初始化页面状态
// 监听 hashchange 事件
window.addEventListener("hashchange", handlePageChange);
// 初始化页面状态
handlePageChange();

return () => {
window.removeEventListener("hashchange", handlePageChange);
Expand All @@ -25,25 +27,17 @@ function MainArea({ page, setPage }) {

const renderPage = () => {
switch (page) {
case '/about':
return <AboutMe />;
case '/experience':
return <Experience />;
case '/projects':
return <Projects />;
case '/resume':
return <Resume />;
case '/privacy':
return <Privacy />;
case '/contactme':
return <ContactMe />;
default:
return <AboutMe />;
case '/about': return <AboutMe />;
case '/experience': return <Experience />;
case '/projects': return <Projects />;
case '/resume': return <Resume />;
case '/privacy': return <Privacy />;
case '/contactme': return <ContactMe />;
default: return <AboutMe key={page} />;
}
};

return <>{renderPage()}</>;
}


export default MainArea;
export default MainArea;

0 comments on commit f0cbaef

Please sign in to comment.