refactor: should use useDocumentTitle to change document title (#2137)

This commit is contained in:
被雨水过滤的空气-Rairn 2023-06-27 18:42:33 +08:00 committed by GitHub
parent dd3e872b06
commit 73dfe074d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -9,7 +9,6 @@ import { useACLRoleContext } from '../acl/ACLProvider';
import { ACLPane } from '../acl/ACLShortcut'; import { ACLPane } from '../acl/ACLShortcut';
import { useRequest } from '../api-client'; import { useRequest } from '../api-client';
import { CollectionManagerPane } from '../collection-manager'; import { CollectionManagerPane } from '../collection-manager';
import { useDocumentTitle } from '../document-title';
import { Icon } from '../icon'; import { Icon } from '../icon';
import { RouteSwitchContext } from '../route-switch'; import { RouteSwitchContext } from '../route-switch';
import { useCompile } from '../schema-component'; import { useCompile } from '../schema-component';
@ -113,7 +112,6 @@ const PluginList = (props) => {
const params = useParams<any>(); const params = useParams<any>();
const navigate = useNavigate(); const navigate = useNavigate();
const { tabName = 'local' } = params; const { tabName = 'local' } = params;
const { setTitle } = useDocumentTitle();
const { t } = useTranslation(); const { t } = useTranslation();
const { snippets = [] } = useACLRoleContext(); const { snippets = [] } = useACLRoleContext();

View File

@ -1,11 +1,11 @@
import { css, cx } from '@emotion/css'; import { css, cx } from '@emotion/css';
import { SortableItem, useCompile, useDesigner } from '@nocobase/client'; import { useField } from '@formily/react';
import { SortableItem, useCompile, useDesigner, useDocumentTitle } from '@nocobase/client';
import { NavBar, NavBarProps } from 'antd-mobile'; import { NavBar, NavBarProps } from 'antd-mobile';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { HeaderDesigner } from './Header.Designer';
import { useField } from '@formily/react';
import { generateNTemplate } from '../../../../locale'; import { generateNTemplate } from '../../../../locale';
import { HeaderDesigner } from './Header.Designer';
export interface HeaderProps extends NavBarProps { export interface HeaderProps extends NavBarProps {
title?: string; title?: string;
@ -18,10 +18,11 @@ const InternalHeader = (props: HeaderProps) => {
const compile = useCompile(); const compile = useCompile();
const compiledTitle = compile(title); const compiledTitle = compile(title);
const navigate = useNavigate(); const navigate = useNavigate();
const { setTitle } = useDocumentTitle();
useEffect(() => { useEffect(() => {
// sync title // sync title
document.title = `${compiledTitle} - NocoBase`; setTitle(compiledTitle);
}, [compiledTitle]); }, [compiledTitle]);
return ( return (