feat: mobileButtonNav active path

This commit is contained in:
shinya
2025-06-23 00:34:23 +08:00
parent 0137527b63
commit 1f7f3d8295
2 changed files with 13 additions and 3 deletions

View File

@@ -14,9 +14,19 @@ import {
import Link from 'next/link';
import { usePathname } from 'next/navigation';
const MobileBottomNav = () => {
interface MobileBottomNavProps {
/**
* 主动指定当前激活的路径。当未提供时,自动使用 usePathname() 获取的路径。
*/
activePath?: string;
}
const MobileBottomNav = ({ activePath }: MobileBottomNavProps) => {
const pathname = usePathname();
// 当前激活路径:优先使用传入的 activePath否则回退到浏览器地址
const currentActive = activePath ?? pathname;
const navItems = [
{ icon: Home, label: '首页', href: '/' },
{ icon: Search, label: '搜索', href: '/search' },
@@ -50,7 +60,7 @@ const MobileBottomNav = () => {
const tagMatch = href.match(/tag=([^&]+)/)?.[1];
// 解码URL以进行正确的比较
const decodedActive = decodeURIComponent(pathname);
const decodedActive = decodeURIComponent(currentActive);
const decodedItemHref = decodeURIComponent(href);
return (

View File

@@ -36,7 +36,7 @@ const PageLayout = ({ children, activePath = '/' }: PageLayoutProps) => {
>
{children}
</main>
<MobileBottomNav />
<MobileBottomNav activePath={activePath} />
</div>
</>
);