blob: cc343b1fd92e8c3c9f2a44a5161b93bebd00d4db [file] [log] [blame]
Krishya2e0f49a2025-05-29 10:59:01 +08001import React from 'react';
2import { Link, useLocation } from 'react-router-dom';
3import './UserNav.css'; // 导入 UserNav 样式文件
4
5const UserNav = () => {
6 const location = useLocation();
7
2230100964011632025-06-04 21:57:22 +08008 // 竖直导航栏的链接项(已添加“新手考核”)
Krishya2e0f49a2025-05-29 10:59:01 +08009 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: '我的收藏' },
2230100964011632025-06-04 21:57:22 +080015 { to: '/user/newbie-tasks', label: '新手考核' },
Krishya2e0f49a2025-05-29 10:59:01 +080016 ];
17
18 // 判断路径是否是当前活动页面
19 const isActive = (path) => location.pathname.startsWith(path);
20
21 return (
22 <div className="user-nav-container">
23 <nav className="user-nav">
24 {navLinks.map(({ to, label }) => (
25 <Link
26 key={to}
27 to={to}
28 className={`user-nav-item ${isActive(to) ? 'active' : ''}`}
29 >
30 {label}
31 </Link>
32 ))}
33 </nav>
34 </div>
35 );
36};
37
38export default UserNav;
39
40// import React from 'react';
41// import './UserNav.css';
42
43// const UserNav = ({ activeKey, onSelect }) => {
44// const navLinks = [
45// { key: 'profile', label: '个人资料' },
46// // { key: 'dynamics', label: '我的动态' },
47// // { key: 'friends', label: '我的好友' },
48// // { key: 'groups', label: '我的群组' },
49// // { key: 'collections', label: '我的收藏' },
2230100964011632025-06-04 21:57:22 +080050// { key: 'newbieTasks', label: '新手考核' },
Krishya2e0f49a2025-05-29 10:59:01 +080051// ];
52
53// return (
54// <div className="user-nav-container">
55// <nav className="user-nav">
56// {navLinks.map(({ key, label }) => (
57// <div
58// key={key}
59// className={`user-nav-item ${activeKey === key ? 'active' : ''}`}
60// onClick={() => onSelect(key)}
61// style={{ cursor: 'pointer' }}
62// >
63// {label}
64// </div>
65// ))}
66// </nav>
67// </div>
68// );
69// };
70
71// export default UserNav;
72