File tree Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Expand file tree Collapse file tree 4 files changed +56
-1
lines changed Original file line number Diff line number Diff line change 1
- import { BrowserRouter as Router , Route , Routes } from 'react-router-dom'
1
+ import { HashRouter as Router , Route , Routes } from 'react-router-dom'
2
2
import './App.css'
3
3
import NavBar from './components/NavBar'
4
4
import HomePage from './components/HomePage'
@@ -7,13 +7,15 @@ import ChallengeDetailPage from './components/ChallengeDetailPage'
7
7
import ChallengeContributePage from './components/ChallengeContributePage'
8
8
import AboutPage from './components/AboutPage'
9
9
import GitHubRibbon from './components/GitHubRibbon'
10
+ import PageTitle from './components/PageTitle'
10
11
import './gh-fork-ribbon.css' ;
11
12
import './styles/github-ribbon-fix.css' ;
12
13
13
14
const App = ( ) => {
14
15
return (
15
16
< Router >
16
17
< div className = "App" >
18
+ < PageTitle />
17
19
< GitHubRibbon repositoryUrl = "https://github.com/JSREP/crawler-leetcode" />
18
20
< NavBar />
19
21
< div className = "content-wrapper" style = { { padding : '20px 0' } } >
Original file line number Diff line number Diff line change
1
+ import { useEffect } from 'react' ;
2
+ import { useLocation } from 'react-router-dom' ;
3
+ import { useTranslation } from 'react-i18next' ;
4
+
5
+ /**
6
+ * 页面标题组件
7
+ * 根据当前路由自动设置文档标题
8
+ */
9
+ const PageTitle = ( ) => {
10
+ const location = useLocation ( ) ;
11
+ const { t } = useTranslation ( ) ;
12
+
13
+ useEffect ( ( ) => {
14
+ let title = t ( 'titles.default' ) ;
15
+
16
+ // 根据路径设置不同的标题
17
+ if ( location . pathname === '/' ) {
18
+ title = t ( 'titles.home' ) ;
19
+ } else if ( location . pathname === '/challenges' ) {
20
+ title = t ( 'titles.challenges' ) ;
21
+ } else if ( location . pathname === '/about' ) {
22
+ title = t ( 'titles.about' ) ;
23
+ } else if ( location . pathname === '/challenge/contribute' ) {
24
+ title = t ( 'titles.contribute' ) ;
25
+ } else if ( location . pathname . startsWith ( '/challenge/' ) ) {
26
+ title = t ( 'titles.challenge' ) ;
27
+ }
28
+
29
+ // 设置文档标题
30
+ document . title = title ;
31
+ } , [ location . pathname , t ] ) ;
32
+
33
+ // 此组件不渲染任何内容
34
+ return null ;
35
+ } ;
36
+
37
+ export default PageTitle ;
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ export default {
7
7
system : 'System' ,
8
8
contribute : 'Contribute'
9
9
} ,
10
+ titles : {
11
+ home : 'Home - Crawler LeetCode' ,
12
+ challenges : 'Challenges - Crawler LeetCode' ,
13
+ about : 'About - Crawler LeetCode' ,
14
+ contribute : 'Contribute - Crawler LeetCode' ,
15
+ challenge : 'Challenge - Crawler LeetCode' ,
16
+ default : 'Crawler LeetCode'
17
+ } ,
10
18
home : {
11
19
hero : {
12
20
title : 'Web Crawler Challenge Collection' ,
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ const zhTranslations = {
7
7
system : '系统' ,
8
8
contribute : '贡献题目'
9
9
} ,
10
+ titles : {
11
+ home : '首页 - 爬虫技术挑战平台' ,
12
+ challenges : '挑战列表 - 爬虫技术挑战平台' ,
13
+ about : '关于 - 爬虫技术挑战平台' ,
14
+ contribute : '贡献题目 - 爬虫技术挑战平台' ,
15
+ challenge : '挑战详情 - 爬虫技术挑战平台' ,
16
+ default : '爬虫技术挑战平台'
17
+ } ,
10
18
home : {
11
19
hero : {
12
20
title : '爬虫技术挑战合集' ,
You can’t perform that action at this time.
0 commit comments