aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/app-routes.tsx
blob: 58747bb0ee03036424070cc89db769283a4cd668 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { ReactNode } from 'react'
import type { LucideIcon } from 'lucide-react'
import { Blocks, House, Info, Shapes } from 'lucide-react'
import { ComponentsRoute } from './components/ComponentsRoute'
import { IconsRoute } from './components/IconsRoute'
import { AboutPage } from './pages/AboutPage'
import { HomePage } from './pages/HomePage'

export interface AppRoute {
  path: string
  label: string
  icon: LucideIcon
  element: ReactNode
  showInNav?: boolean
}

/**
 * 页面、路由和侧边栏的唯一数据源。
 * 新增页面时只在这里增加一项,路由与菜单会同步更新。
 */
export const appRoutes: AppRoute[] = [
  {
    path: '/',
    label: '概览',
    icon: House,
    element: <HomePage />,
  },
  {
    path: '/components',
    label: '组件',
    icon: Blocks,
    element: <ComponentsRoute />,
  },
  {
    path: '/icons',
    label: '图标',
    icon: Shapes,
    element: <IconsRoute />,
  },
  {
    path: '/about',
    label: '关于',
    icon: Info,
    element: <AboutPage />,
  },
]

export const navRoutes = appRoutes.filter(
  (route) => route.showInNav !== false,
)

export function isRouteActive(routePath: string, pathname: string) {
  return routePath === '/'
    ? pathname === '/'
    : pathname === routePath || pathname.startsWith(`${routePath}/`)
}