22301009 | bcedb11 | 2025-04-15 21:32:19 +0800 | [diff] [blame^] | 1 | import React from 'react'; |
| 2 | import { Link, useLocation } from 'react-router-dom'; |
| 3 | import './UserNav.css'; // 导入 UserNav 样式文件 |
| 4 | |
| 5 | const UserNav = () => { |
| 6 | const location = useLocation(); |
| 7 | |
| 8 | // 竖直导航栏的链接项 |
| 9 | const navLinks = [ |
| 10 | { to: '/user/profile', label: '个人资料' }, |
| 11 | { to: '/user/dynamics', label: '我的动态' }, |
| 12 | { to: '/user/friends', label: '我的好友' }, |
| 13 | { to: '/user/groups', label: '我的群组' }, |
| 14 | { to: '/user/collections', label: '我的收藏' }, |
| 15 | ]; |
| 16 | |
| 17 | // 判断路径是否是当前活动页面 |
| 18 | const isActive = (path) => location.pathname.startsWith(path); |
| 19 | |
| 20 | return ( |
| 21 | <div className="user-nav-container"> |
| 22 | <nav className="user-nav"> |
| 23 | {navLinks.map(({ to, label }) => ( |
| 24 | <Link |
| 25 | key={to} |
| 26 | to={to} |
| 27 | className={`user-nav-item ${isActive(to) ? 'active' : ''}`} |
| 28 | > |
| 29 | {label} |
| 30 | </Link> |
| 31 | ))} |
| 32 | </nav> |
| 33 | </div> |
| 34 | ); |
| 35 | }; |
| 36 | |
| 37 | export default UserNav; |
| 38 | s |