forked from zhongyidian/food-add-edu
- 添加 React Router 和 Tailwind CSS 依赖 - 移除旧的 CSS 文件,改用模块化样式 - 更新 lint-staged 配置以跳过 CSS 文件 - 重构 App 组件以使用新的导航和样式
43 lines
839 B
TypeScript
43 lines
839 B
TypeScript
import { Link, useLocation } from "react-router-dom";
|
|
import { cn } from "../../../lib/utils.ts";
|
|
import styles from "./Navigation.module.css";
|
|
|
|
interface NavItem {
|
|
label: string;
|
|
path: string;
|
|
}
|
|
|
|
interface NavigationProps {
|
|
items?: NavItem[];
|
|
className?: string;
|
|
}
|
|
|
|
const defaultItems: NavItem[] = [
|
|
{ label: "首页", path: "/" },
|
|
{ label: "关于", path: "/about" },
|
|
];
|
|
|
|
export function Navigation({
|
|
items = defaultItems,
|
|
className,
|
|
}: NavigationProps) {
|
|
const location = useLocation();
|
|
|
|
return (
|
|
<nav className={cn(styles.navigation, className)}>
|
|
{items.map((item) => {
|
|
const isActive = location.pathname === item.path;
|
|
return (
|
|
<Link
|
|
key={item.path}
|
|
to={item.path}
|
|
className={cn(styles.link, isActive && styles.active)}
|
|
>
|
|
{item.label}
|
|
</Link>
|
|
);
|
|
})}
|
|
</nav>
|
|
);
|
|
}
|