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'
22import './App.css'
33import NavBar from './components/NavBar'
44import HomePage from './components/HomePage'
@@ -7,13 +7,15 @@ import ChallengeDetailPage from './components/ChallengeDetailPage'
77import ChallengeContributePage from './components/ChallengeContributePage'
88import AboutPage from './components/AboutPage'
99import GitHubRibbon from './components/GitHubRibbon'
10+ import PageTitle from './components/PageTitle'
1011import './gh-fork-ribbon.css' ;
1112import './styles/github-ribbon-fix.css' ;
1213
1314const App = ( ) => {
1415 return (
1516 < Router >
1617 < div className = "App" >
18+ < PageTitle />
1719 < GitHubRibbon repositoryUrl = "https://github.com/JSREP/crawler-leetcode" />
1820 < NavBar />
1921 < 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 {
77 system : 'System' ,
88 contribute : 'Contribute'
99 } ,
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+ } ,
1018 home : {
1119 hero : {
1220 title : 'Web Crawler Challenge Collection' ,
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ const zhTranslations = {
77 system : '系统' ,
88 contribute : '贡献题目'
99 } ,
10+ titles : {
11+ home : '首页 - 爬虫技术挑战平台' ,
12+ challenges : '挑战列表 - 爬虫技术挑战平台' ,
13+ about : '关于 - 爬虫技术挑战平台' ,
14+ contribute : '贡献题目 - 爬虫技术挑战平台' ,
15+ challenge : '挑战详情 - 爬虫技术挑战平台' ,
16+ default : '爬虫技术挑战平台'
17+ } ,
1018 home : {
1119 hero : {
1220 title : '爬虫技术挑战合集' ,
You can’t perform that action at this time.
0 commit comments