Skip to content

Commit 4a1331f

Browse files
committed
fixed route and hemlt
1 parent bcedc3d commit 4a1331f

File tree

4 files changed

+83
-13
lines changed

4 files changed

+83
-13
lines changed

package-lock.json

+36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@testing-library/user-event": "^13.5.0",
99
"react": "^18.3.1",
1010
"react-dom": "^18.3.1",
11+
"react-helmet-async": "^2.0.5",
1112
"react-icons": "^5.3.0",
1213
"react-router-dom": "^6.28.0",
1314
"react-scripts": "5.0.1",

src/App.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { BrowserRouter } from 'react-router-dom';
2+
import { HelmetProvider } from 'react-helmet-async';
13
import HomePage from './components/HomePage';
24
import HostSection from './components/HostSection';
35
import SponsorsSection from './components/SponsorsSection';
@@ -6,13 +8,17 @@ import Footer from './components/Footer';
68

79
function App() {
810
return (
9-
<div className="App">
10-
<HomePage />
11-
<HostSection />
12-
<SponsorsSection />
13-
<SpeakersSection />
14-
<Footer />
15-
</div>
11+
<HelmetProvider>
12+
<BrowserRouter>
13+
<div className="App">
14+
<HomePage />
15+
<HostSection id="hosts" />
16+
<SponsorsSection id="sponsors" />
17+
<SpeakersSection id="speakers" />
18+
<Footer />
19+
</div>
20+
</BrowserRouter>
21+
</HelmetProvider>
1622
);
1723
}
1824

src/components/HomePage.jsx

+33-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
2+
import { useLocation } from 'react-router-dom';
3+
import { Helmet } from 'react-helmet-async';
24
import Logo from './Logo';
35

46
const HomePage = () => {
7+
const location = useLocation();
58
const [isMenuOpen, setIsMenuOpen] = useState(false);
69

10+
// Handle direct URL access
11+
useEffect(() => {
12+
const hash = location.pathname.replace('/', '');
13+
if (hash) {
14+
const element = document.getElementById(hash);
15+
if (element) {
16+
setTimeout(() => {
17+
element.scrollIntoView({ behavior: 'smooth' });
18+
}, 100);
19+
}
20+
}
21+
}, [location]);
22+
723
return (
824
<div className="min-h-screen bg-white relative">
25+
<Helmet>
26+
<title>JSDC 2024 - JavaScript 開發者年會</title>
27+
<meta name="description" content="JSDC 2024 JavaScript 開發者年會,12月21日線上活動" />
28+
<meta property="og:title" content="JSDC 2024 - JavaScript 開發者年會" />
29+
<meta property="og:description" content="JSDC 2024 JavaScript 開發者年會,12月21日線上活動" />
30+
<link rel="canonical" href={`https://yourwebsite.com${location.pathname}`} />
31+
</Helmet>
32+
933
{/* Navigation */}
1034
<nav className="absolute top-0 left-0 right-0 p-4 flex justify-center items-center">
1135
<div className="w-full max-w-6xl flex justify-between items-center">
@@ -26,8 +50,9 @@ const HomePage = () => {
2650

2751
{/* Desktop Menu */}
2852
<div className="hidden md:flex space-x-6 text-sm items-center">
29-
<a href="#speakers" className="hover:text-gray-600 flex items-center" onClick={(e) => {
53+
<a href="/speakers" className="hover:text-gray-600 flex items-center" onClick={(e) => {
3054
e.preventDefault();
55+
window.history.pushState({}, '', '/speakers');
3156
document.querySelector('#speakers').scrollIntoView({ behavior: 'smooth' });
3257
}}>SPEAKERS</a>
3358
<a href="#sponsors" className="hover:text-gray-600 flex items-center" onClick={(e) => {
@@ -94,8 +119,9 @@ const HomePage = () => {
94119
$jsdcTitle.textContent = 'JSDC 2024 IS HERE.';
95120
}, 5000);
96121
}}>SPONSORS</a>
97-
<a href="#hosts" className="hover:text-gray-600 flex items-center" onClick={(e) => {
122+
<a href="/hosts" className="hover:text-gray-600 flex items-center" onClick={(e) => {
98123
e.preventDefault();
124+
window.history.pushState({}, '', '/hosts');
99125
document.querySelector('#hosts').scrollIntoView({ behavior: 'smooth' });
100126
}}>HOST</a>
101127
<a
@@ -116,8 +142,9 @@ const HomePage = () => {
116142
md:hidden
117143
`}>
118144
<div className="flex flex-col space-y-8 text-xl">
119-
<a href="#speakers" className="hover:text-gray-600" onClick={(e) => {
145+
<a href="/speakers" className="hover:text-gray-600" onClick={(e) => {
120146
e.preventDefault();
147+
window.history.pushState({}, '', '/speakers');
121148
document.querySelector('#speakers').scrollIntoView({ behavior: 'smooth' });
122149
setTimeout(() => setIsMenuOpen(false), 100);
123150
}}>SPEAKERS</a>
@@ -188,9 +215,9 @@ const HomePage = () => {
188215
}, 5000);
189216
}, 300);
190217
}}>SPONSORS</a>
191-
<a href="#hosts" className="hover:text-gray-600" onClick={(e) => {
218+
<a href="/hosts" className="hover:text-gray-600" onClick={(e) => {
192219
e.preventDefault();
193-
setIsMenuOpen(false);
220+
window.history.pushState({}, '', '/hosts');
194221
document.querySelector('#hosts').scrollIntoView({ behavior: 'smooth' });
195222
setTimeout(() => setIsMenuOpen(false), 100);
196223
}}>HOST</a>

0 commit comments

Comments
 (0)