| import React from 'react'; |
| import { Link, useLocation } from 'react-router-dom'; // 引入 useLocation 钩子 |
| import './Header.css'; // 导入 Header.css 文件 |
| import logo from '../assets/logo.png'; |
| |
| const Header = () => { |
| const location = useLocation(); // 获取当前路径 |
| |
| // 判断路径是否是种子列表相关 |
| const isSeedListActive = location.pathname.startsWith('/seed-list') || location.pathname.startsWith('/seed/'); |
| |
| return ( |
| <div className="main-page"> |
| {/* 顶部栏 */} |
| <header className="header"> |
| {/* 左侧 logo 和网站名称 */} |
| <div className="logo-and-name"> |
| <img src={logo} alt="网站 logo" className="logo" /> |
| <span className="site-name">Echo</span> |
| </div> |
| {/* 右侧用户头像和消息中心 */} |
| <div className="user-and-message"> |
| <img src="user-avatar.png" alt="用户头像" className="user-avatar" /> |
| <span className="message-center">消息</span> |
| </div> |
| </header> |
| {/* 导航栏 */} |
| <nav className="nav"> |
| <Link to="/friend-moments" className="nav-item">好友动态</Link> |
| <Link to="/forum" className="nav-item">论坛</Link> |
| <Link to="/interest-groups" className="nav-item">兴趣小组</Link> |
| <Link to="/seed-list" className={`nav-item ${isSeedListActive ? 'active' : ''}`}>种子列表</Link> {/* 动态添加 active 类 */} |
| <Link to="/publish-seed" className="nav-item">发布种子</Link> |
| </nav> |
| </div> |
| ); |
| }; |
| |
| export default Header; |