From e65692fbdda4f522108b9a04c878d7b83ac2bff4 Mon Sep 17 00:00:00 2001 From: gary-Shen Date: Thu, 16 Nov 2023 14:08:34 +0800 Subject: [PATCH] docs: update title --- src/components/router-container/index.tsx | 6 ++++-- src/locale/resources/en-US.json | 1 + src/locale/resources/zh-CN.json | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/router-container/index.tsx b/src/components/router-container/index.tsx index 2e6850d2..2b9cf5a5 100644 --- a/src/components/router-container/index.tsx +++ b/src/components/router-container/index.tsx @@ -3,6 +3,7 @@ * 见:https://reactrouter.com/en/main/routers/picking-a-router */ import React, { useEffect, useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; import type { RouteObject, UIMatch } from 'react-router-dom'; import { createHashRouter, createRoutesFromElements, Route, RouterProvider, useMatches } from 'react-router-dom'; @@ -14,16 +15,17 @@ export type Match = UIMatch string }>; // 将对应的面包屑信息添加到页面标题中 function RouteWithTitle({ children }: { children: React.ReactNode }) { + const { t } = useTranslation(); const matches = useMatches() as Match[]; const titles = useMemo( () => matches.filter((match) => Boolean(match.handle?.crumb)).map((match) => match.handle.crumb!(match.data)), [matches], ); - const title = titles.length > 0 ? titles[titles.length - 1] : null; + const title = titles.length > 0 ? titles.join(' / ') : null; useEffect(() => { - document.title = title ? `${title} - LabelU` : 'LabelU'; + document.title = title ? `${title} - ${t('site.title')}` : t('site.title'); }, [title]); return <>{children}; diff --git a/src/locale/resources/en-US.json b/src/locale/resources/en-US.json index 52019a15..0b2ed22b 100644 --- a/src/locale/resources/en-US.json +++ b/src/locale/resources/en-US.json @@ -1,4 +1,5 @@ { + "site.title": "LabelU Guide", "guide": "Guide", "guide.intro": "Introduction", "guide.intro.product": "Overview", diff --git a/src/locale/resources/zh-CN.json b/src/locale/resources/zh-CN.json index 66811a28..ab9eff6a 100644 --- a/src/locale/resources/zh-CN.json +++ b/src/locale/resources/zh-CN.json @@ -1,4 +1,5 @@ { + "site.title": "LabelU 使用指南", "guide": "使用指南", "guide.intro": "产品介绍", "guide.intro.product": "介绍",