fix: page title refresh (#4186)

* fix: ts

* update jieba package

* fix: page title refresh
This commit is contained in:
Archer 2025-03-17 10:53:38 +08:00 committed by archer
parent cf50f9ec4d
commit dec47ce8d3
No known key found for this signature in database
GPG Key ID: 4446499B846D4A9E
3 changed files with 27 additions and 17 deletions

View File

@ -35,3 +35,4 @@ weight: 799
7. 新增自定义模型时,会把默认模型字段也保存,导致默认模型误判。
8. 修复 promp 模式工具调用,未判空思考链,导致 UI 错误展示。
9. 编辑应用信息导致头像丢失。
10. 分享链接标题会被刷新掉。

View File

@ -1,6 +1,6 @@
import { LOGO_ICON } from '@fastgpt/global/common/system/constants';
import Head from 'next/head';
import React, { useEffect, useMemo } from 'react';
import React, { useMemo } from 'react';
const NextHead = ({ title, icon, desc }: { title?: string; icon?: string; desc?: string }) => {
const formatIcon = useMemo(() => {
@ -11,13 +11,6 @@ const NextHead = ({ title, icon, desc }: { title?: string; icon?: string; desc?:
return LOGO_ICON;
}, [icon]);
useEffect(() => {
// Force update document title
if (title) {
document.title = title;
}
}, [title]);
return (
<Head>
<title>{title}</title>

View File

@ -15,6 +15,7 @@ import { ReactElement, useEffect } from 'react';
import { NextPage } from 'next';
import { getWebReqUrl } from '@fastgpt/web/common/system/utils';
import SystemStoreContextProvider from '@fastgpt/web/context/useSystem';
import { useRouter } from 'next/router';
type NextPageWithLayout = NextPage & {
setLayout?: (page: ReactElement) => JSX.Element;
@ -23,6 +24,15 @@ type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};
// 哪些路由有自定义 Head
const routesWithCustomHead = [
'/chat',
'/chat/share',
'chat/team',
'/app/detail/',
'/dataset/detail'
];
function App({ Component, pageProps }: AppPropsWithLayout) {
const { feConfigs, scripts, title } = useInitApp();
const { t } = useTranslation();
@ -42,17 +52,23 @@ function App({ Component, pageProps }: AppPropsWithLayout) {
const setLayout = Component.setLayout || ((page) => <>{page}</>);
const router = useRouter();
const showHead = !router?.pathname || !routesWithCustomHead.includes(router.pathname);
return (
<>
<NextHead
title={title}
desc={
feConfigs?.systemDescription ||
process.env.SYSTEM_DESCRIPTION ||
`${title}${t('app:intro')}`
}
icon={getWebReqUrl(feConfigs?.favicon || process.env.SYSTEM_FAVICON)}
/>
{showHead && (
<NextHead
title={title}
desc={
feConfigs?.systemDescription ||
process.env.SYSTEM_DESCRIPTION ||
`${title}${t('app:intro')}`
}
icon={getWebReqUrl(feConfigs?.favicon || process.env.SYSTEM_FAVICON)}
/>
)}
{scripts?.map((item, i) => <Script key={i} strategy="lazyOnload" {...item}></Script>)}
<QueryClientContext>