18f534bbd6
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Validate - Code Quality (push) Successful in 5m15s
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 2m3s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 2m22s
CI/CD Pipeline / Unit Tests (push) Successful in 7m55s
CI/CD Pipeline / Integration Tests (push) Successful in 3m4s
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 1m42s
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Build Staging API Image (push) Successful in 19m15s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 2m35s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 8m9s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m38s
CI/CD Pipeline / Staging E2E Tests (push) Blocked by required conditions
CI/CD Pipeline / Staging API Integration Tests (push) Blocked by required conditions
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (push) Blocked by required conditions
CI/CD Pipeline / Canary Release to Production (push) Blocked by required conditions
CI/CD Pipeline / CI Gate (push) Has been skipped
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { ROUTE_TITLE_MAP } from "./constants"
|
|
import type { BreadcrumbItem } from "./types"
|
|
|
|
/** 根据当前路径生成面包屑 */
|
|
export const generateBreadcrumb = (pathname: string): BreadcrumbItem[] => {
|
|
const items: BreadcrumbItem[] = [{ label: "首页", path: "/app/dashboard" }]
|
|
|
|
// 首页本身不需要面包屑
|
|
if (pathname === "/app" || pathname === "/app/dashboard") {
|
|
return items
|
|
}
|
|
|
|
// 逐级拆分路径,生成中间层级
|
|
const segments = pathname.split("/").filter(Boolean)
|
|
let currentPath = ""
|
|
|
|
for (let i = 0; i < segments.length; i++) {
|
|
currentPath += `/${segments[i]}`
|
|
const title = ROUTE_TITLE_MAP[currentPath]
|
|
|
|
if (title) {
|
|
// 最后一级不带 path(当前页面,不可点击)
|
|
const isLast = i === segments.length - 1
|
|
items.push({
|
|
label: title,
|
|
path: isLast ? undefined : currentPath,
|
|
})
|
|
} else {
|
|
// 动态路由段(如 :id),用路径片段做 label
|
|
const isLast = i === segments.length - 1
|
|
items.push({
|
|
label: segments[i],
|
|
path: isLast ? undefined : currentPath,
|
|
})
|
|
}
|
|
}
|
|
|
|
return items
|
|
}
|