mirror of
https://github.com/DerTyp7/dertyp7.github.io.git
synced 2025-10-29 04:42:08 +01:00
Add HashRouter to main.tsx and update dependencies
This commit is contained in:
848
package-lock.json
generated
848
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@@ -11,20 +11,22 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/react-router-dom": "^5.3.3",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"sass": "^1.68.0"
|
"react-router-dom": "^6.21.2",
|
||||||
|
"sass": "^1.69.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/react": "^18.2.15",
|
"@types/react": "^18.2.47",
|
||||||
"@types/react-dom": "^18.2.7",
|
"@types/react-dom": "^18.2.18",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
"@typescript-eslint/eslint-plugin": "^6.18.1",
|
||||||
"@typescript-eslint/parser": "^6.0.0",
|
"@typescript-eslint/parser": "^6.18.1",
|
||||||
"@vitejs/plugin-react-swc": "^3.3.2",
|
"@vitejs/plugin-react-swc": "^3.5.0",
|
||||||
"eslint": "^8.45.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-plugin-react-hooks": "^4.6.0",
|
"eslint-plugin-react-hooks": "^4.6.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.3",
|
"eslint-plugin-react-refresh": "^0.4.5",
|
||||||
"typescript": "^5.0.2",
|
"typescript": "^5.3.3",
|
||||||
"vite": "^4.4.5"
|
"vite": "^5.0.11"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/App.tsx
52
src/App.tsx
@@ -1,24 +1,58 @@
|
|||||||
|
import { useEffect, useRef } from "react";
|
||||||
import "@styles/App.scss";
|
import "@styles/App.scss";
|
||||||
import Header from "@components/Header";
|
import Header from "@components/Header";
|
||||||
import About from "@components/About";
|
import About from "@components/About";
|
||||||
import ScrollToTop from "@components/ScrollToTop";
|
import ScrollToTop from "@components/ScrollToTop";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
|
const aboutRef = useRef(null);
|
||||||
|
const skillsRef = useRef(null);
|
||||||
|
const projectsRef = useRef(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const observer = new IntersectionObserver(
|
||||||
|
(entries) => {
|
||||||
|
entries.forEach((entry) => {
|
||||||
|
if (entry.isIntersecting) {
|
||||||
|
window.location.hash = entry.target.id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
{ threshold: 0.7 }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (aboutRef.current) {
|
||||||
|
observer.observe(aboutRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skillsRef.current) {
|
||||||
|
observer.observe(skillsRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (projectsRef.current) {
|
||||||
|
observer.observe(projectsRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
observer.disconnect();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<Header />
|
<Header />
|
||||||
|
<div id="about" ref={aboutRef}>
|
||||||
<About />
|
<About />
|
||||||
<div id="skills">
|
|
||||||
<h4>
|
|
||||||
<a href="#skills">Skills</a>
|
|
||||||
</h4>
|
|
||||||
<h4>
|
|
||||||
<a href="#projects">Projects</a>
|
|
||||||
</h4>
|
|
||||||
</div>
|
</div>
|
||||||
<div style={{ textAlign: "center" }}>
|
|
||||||
|
<div id="skills" ref={skillsRef}>
|
||||||
|
<h4>Skills</h4>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="projects" ref={projectsRef} style={{ textAlign: "center" }}>
|
||||||
|
<h4>Projects</h4>
|
||||||
|
</div>
|
||||||
<h4>Website under construction 🚧👷</h4>
|
<h4>Website under construction 🚧👷</h4>
|
||||||
</div>
|
|
||||||
<ScrollToTop />
|
<ScrollToTop />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import "@styles/Burger.scss";
|
import "@styles/Burger.scss";
|
||||||
|
|
||||||
export default function Burger({ onClick }: { onClick: () => void }) {
|
export default function Burger({
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
isOpen,
|
||||||
|
onClick,
|
||||||
const toggleMenu = () => {
|
}: {
|
||||||
setIsOpen(!isOpen);
|
isOpen: boolean;
|
||||||
};
|
onClick: () => void;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`burger ${isOpen ? "open" : ""}`}
|
className={`burger ${isOpen ? "open" : ""}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
toggleMenu();
|
|
||||||
onClick();
|
onClick();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ import "@styles/Header.scss";
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import Burger from "@components/Burger";
|
import Burger from "@components/Burger";
|
||||||
import Sidebar from "@components/Sidebar";
|
import Sidebar from "@components/Sidebar";
|
||||||
|
import { useLocation } from "react-router-dom";
|
||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
const [isSmallScreen, setIsSmallScreen] = useState(window.innerWidth <= 768);
|
const [isSmallScreen, setIsSmallScreen] = useState(window.innerWidth <= 768);
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
const toggleSidebar = () => setIsOpen(!isOpen);
|
const toggleSidebar = () => setIsOpen(!isOpen);
|
||||||
|
|
||||||
@@ -27,16 +29,33 @@ export default function Header() {
|
|||||||
|
|
||||||
{isSmallScreen ? (
|
{isSmallScreen ? (
|
||||||
<>
|
<>
|
||||||
<Burger onClick={toggleSidebar} />
|
<Burger isOpen={isOpen} onClick={toggleSidebar} />
|
||||||
<Sidebar isOpen={isOpen} toggle={toggleSidebar} />
|
<Sidebar isOpen={isOpen} toggle={toggleSidebar} />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<nav>
|
<nav>
|
||||||
<a className="current" href="#">
|
<a
|
||||||
|
className={
|
||||||
|
location.pathname === "/about" || location.pathname === "/"
|
||||||
|
? "current"
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
href="#"
|
||||||
|
>
|
||||||
About
|
About
|
||||||
</a>
|
</a>
|
||||||
<a href="#skills">Skills</a>
|
<a
|
||||||
<a href="#projects">Projects</a>
|
className={location.pathname === "/skills" ? "current" : ""}
|
||||||
|
href="#skills"
|
||||||
|
>
|
||||||
|
Skills
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
className={location.pathname === "/projects" ? "current" : ""}
|
||||||
|
href="#projects"
|
||||||
|
>
|
||||||
|
Projects
|
||||||
|
</a>
|
||||||
</nav>
|
</nav>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import App from "./App.tsx";
|
import App from "./App.tsx";
|
||||||
|
import { HashRouter } from "react-router-dom";
|
||||||
import "@styles/index.scss";
|
import "@styles/index.scss";
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root")!).render(
|
ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
<HashRouter>
|
||||||
<App />
|
<App />
|
||||||
|
</HashRouter>
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user