zhouxiantao
8 days ago 03193b2a27a2c23e10f3a2f298de9c1142116780
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
 * @author 韩天尊
 * @time 2024-01-15
 * @version 1.0.0
 * @description 底部导航组件
 */
import React from 'react';
import { useNavigate, useLocation } from 'react-router-dom';
 
const BottomNavigation: React.FC = () => {
    const navigate = useNavigate();
    const location = useLocation();
 
    // 判断当前页面是否为首页
    const isHome = location.pathname === '/';
    const isProfile = location.pathname === '/profile';
 
    const handleNavigation = (route: string) => {
        if (route === 'home') {
            navigate('/');
        } else if (route === 'profile') {
            navigate('/profile');
        }
    };
 
    return (
        <div className="bottom-nav">
            <div 
                className={`nav-item ${isHome ? 'active' : ''}`}
                onClick={() => handleNavigation('home')}
            >
                <i className="fas fa-home"></i>
                <span>首页</span>
            </div>
            <div 
                className={`nav-item ${isProfile ? 'active' : ''}`}
                onClick={() => handleNavigation('profile')}
            >
                <i className="fas fa-user"></i>
                <span>我的</span>
            </div>
        </div>
    );
};
 
export default BottomNavigation;