blob: 4bd76db77b6857a277919cc6290889bf2c53dad6 [file] [log] [blame]
22301009bcedb112025-04-15 21:32:19 +08001import React from 'react';
2import { Link, useLocation } from 'react-router-dom';
3import './UserNav.css'; // 导入 UserNav 样式文件
4
5const 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
223010097ff51f22025-04-15 21:35:28 +080037export default UserNav;