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' ;
2
4
import Logo from './Logo' ;
3
5
4
6
const HomePage = ( ) => {
7
+ const location = useLocation ( ) ;
5
8
const [ isMenuOpen , setIsMenuOpen ] = useState ( false ) ;
6
9
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
+
7
23
return (
8
24
< 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
+
9
33
{ /* Navigation */ }
10
34
< nav className = "absolute top-0 left-0 right-0 p-4 flex justify-center items-center" >
11
35
< div className = "w-full max-w-6xl flex justify-between items-center" >
@@ -26,8 +50,9 @@ const HomePage = () => {
26
50
27
51
{ /* Desktop Menu */ }
28
52
< 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 ) => {
30
54
e . preventDefault ( ) ;
55
+ window . history . pushState ( { } , '' , '/speakers' ) ;
31
56
document . querySelector ( '#speakers' ) . scrollIntoView ( { behavior : 'smooth' } ) ;
32
57
} } > SPEAKERS</ a >
33
58
< a href = "#sponsors" className = "hover:text-gray-600 flex items-center" onClick = { ( e ) => {
@@ -94,8 +119,9 @@ const HomePage = () => {
94
119
$jsdcTitle . textContent = 'JSDC 2024 IS HERE.' ;
95
120
} , 5000 ) ;
96
121
} } > 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 ) => {
98
123
e . preventDefault ( ) ;
124
+ window . history . pushState ( { } , '' , '/hosts' ) ;
99
125
document . querySelector ( '#hosts' ) . scrollIntoView ( { behavior : 'smooth' } ) ;
100
126
} } > HOST</ a >
101
127
< a
@@ -116,8 +142,9 @@ const HomePage = () => {
116
142
md:hidden
117
143
` } >
118
144
< 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 ) => {
120
146
e . preventDefault ( ) ;
147
+ window . history . pushState ( { } , '' , '/speakers' ) ;
121
148
document . querySelector ( '#speakers' ) . scrollIntoView ( { behavior : 'smooth' } ) ;
122
149
setTimeout ( ( ) => setIsMenuOpen ( false ) , 100 ) ;
123
150
} } > SPEAKERS</ a >
@@ -188,9 +215,9 @@ const HomePage = () => {
188
215
} , 5000 ) ;
189
216
} , 300 ) ;
190
217
} } > SPONSORS</ a >
191
- < a href = "# hosts" className = "hover:text-gray-600" onClick = { ( e ) => {
218
+ < a href = "/ hosts" className = "hover:text-gray-600" onClick = { ( e ) => {
192
219
e . preventDefault ( ) ;
193
- setIsMenuOpen ( false ) ;
220
+ window . history . pushState ( { } , '' , '/hosts' ) ;
194
221
document . querySelector ( '#hosts' ) . scrollIntoView ( { behavior : 'smooth' } ) ;
195
222
setTimeout ( ( ) => setIsMenuOpen ( false ) , 100 ) ;
196
223
} } > HOST</ a >
0 commit comments