Skip to content

Commit

Permalink
docs: update title
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-Shen committed Nov 16, 2023
1 parent 342fb43 commit e65692f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/router-container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -14,16 +15,17 @@ export type Match = UIMatch<any, { crumb: (data: any) => 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}</>;
Expand Down
1 change: 1 addition & 0 deletions src/locale/resources/en-US.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"site.title": "LabelU Guide",
"guide": "Guide",
"guide.intro": "Introduction",
"guide.intro.product": "Overview",
Expand Down
1 change: 1 addition & 0 deletions src/locale/resources/zh-CN.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"site.title": "LabelU 使用指南",
"guide": "使用指南",
"guide.intro": "产品介绍",
"guide.intro.product": "介绍",
Expand Down

0 comments on commit e65692f

Please sign in to comment.