feat(web): 地址栏驱动视图,刷新详情页不再回首页

- 新增 data/view.ts 与 useViewRoute:视图与地址双向同步,支持前进后退
- 条目地址带上所属分组,刷新 / 收藏后「返回」有确定落点
- 服务端只把 /c/** 回落到 index.html,其余路径仍返回 404
- 明细页返回按钮去掉左侧箭头图标
This commit is contained in:
2026-10-24 17:18:30 +08:00
parent 41fed5e64d
commit 19ead7b716
22 changed files with 2098 additions and 1321 deletions
-6
View File
@@ -1,6 +1,5 @@
import { useCallback, useEffect, useRef, useState } from 'react'
import { fetchCatalog, subscribeCatalog } from './api'
import { EMPTY_NAV, type NavModel } from './data/nav'
import type { Category } from './data/types'
export type CatalogStatus = 'loading' | 'ready' | 'error'
@@ -8,8 +7,6 @@ export type CatalogStatus = 'loading' | 'ready' | 'error'
export type CatalogState = {
status: CatalogStatus
categories: Category[]
/** 侧栏导航;与分类同一次请求下发 */
nav: NavModel
error: string | null
}
@@ -32,7 +29,6 @@ export function useCatalog(): CatalogController {
const [state, setState] = useState<CatalogState>({
status: 'loading',
categories: [],
nav: EMPTY_NAV,
error: null,
})
const controllerRef = useRef<AbortController | null>(null)
@@ -54,7 +50,6 @@ export function useCatalog(): CatalogController {
setState({
status: 'ready',
categories: catalog.categories,
nav: catalog.nav,
error: null,
})
}
@@ -65,7 +60,6 @@ export function useCatalog(): CatalogController {
// 已经有内容时只提示错误,不清空列表
status: previous.categories.length > 0 ? 'ready' : 'error',
categories: previous.categories,
nav: previous.nav,
error: toErrorMessage(error),
}))
}