F2-13: Tab 深链接 + schema title 回填(直开 /page/:id 自动建 Tab)
根因:直接输入 URL /page/:id 时,路由不在 tabs 列表中导致无法激活, Tab 标题也只显示 templateId 而非真实页面标题。 修法: 1. AppShell useEffect:/page/ 深链接路由自动加入 tabs 并激活 2. TabTitleContext:提供 updateTabTitle 回调给子路由 3. PageRenderPage:schema 加载成功后调 updateTabTitle 回填真实 title Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import { useParams } from 'react-router-dom';
|
||||
import { fetchSchema } from '../api/schema';
|
||||
import { AmisRenderer } from '../components/AmisRenderer';
|
||||
import { recordRecentPage } from '../utils/recentPages';
|
||||
import { useTabTitle } from '../shell/TabTitleContext';
|
||||
|
||||
// ---- amis 渲染层错误边界(class component,捕获子树抛错)----
|
||||
interface ErrorBoundaryState {
|
||||
@@ -73,6 +74,7 @@ export function PageRenderPage() {
|
||||
const { templateId = '' } = useParams();
|
||||
const [schema, setSchema] = useState<Record<string, unknown> | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
const { updateTabTitle } = useTabTitle();
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
@@ -90,6 +92,8 @@ export function PageRenderPage() {
|
||||
// 渲染成功后写入最近打开(title 取 schema.title 或 templateId)
|
||||
const title = (s['title'] as string) || templateId;
|
||||
recordRecentPage({ templateId, name: title, path: title });
|
||||
// F2-13:回填 Tab 标题为 schema title
|
||||
updateTabTitle(`/page/${templateId}`, title);
|
||||
})
|
||||
.catch((e: Error) => {
|
||||
if (alive) setError(e.message ?? '未知错误');
|
||||
|
||||
Reference in New Issue
Block a user