feat: add layout header which ensure title of page is correct

This commit is contained in:
moonrailgun 2024-04-22 00:01:18 +08:00
parent e2fc9224c7
commit 120df2d8b5
3 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,18 @@
import { useUserInfo } from '@/store/user';
import React from 'react';
import { Helmet } from 'react-helmet';
export const LayoutHeader: React.FC = React.memo(() => {
const userInfo = useUserInfo();
let title = 'Tianji - Insight into everything';
if (userInfo) {
title = userInfo.currentWorkspace.name + ' | ' + title;
}
return (
<Helmet>
<title>{title}</title>
</Helmet>
);
});
LayoutHeader.displayName = 'LayoutHeader';

View File

@ -1,3 +1,4 @@
import { LayoutHeader } from '@/pages/Layout/Header';
import { createRootRouteWithContext, Outlet } from '@tanstack/react-router';
// import { TanStackRouterDevtools } from '@tanstack/router-devtools';
import { Suspense } from 'react';
@ -12,6 +13,8 @@ export const Route = createRootRouteWithContext<RouterContext>()({
return (
// https://github.com/TanStack/router/issues/857
<Suspense fallback={null}>
<LayoutHeader />
<Outlet />
{/* <TanStackRouterDevtools position="bottom-right" /> */}

View File

@ -3,7 +3,6 @@ import { ErrorTip } from '@/components/ErrorTip';
import { Loading } from '@/components/Loading';
import { NotFoundTip } from '@/components/NotFoundTip';
import { MonitorStatusPage } from '@/components/monitor/StatusPage';
import { Button } from '@/components/ui/button';
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/status/$slug')({