Skip to content

Commit

Permalink
Fix Active Nav Link (#1107)
Browse files Browse the repository at this point in the history
Fixed active nav link issue
  • Loading branch information
zulalnb authored Oct 4, 2024
1 parent 6d112b9 commit c8a6537
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/hooks/useSelectedPathname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client";

import { useParams, usePathname } from "next/navigation";

function useSelectedPathname() {
const pathname = usePathname();

const { channel } = useParams<{ channel?: string }>();

const selectedPathname = channel ? pathname.replace(`/${channel}`, "") : pathname;
return selectedPathname;
}

export default useSelectedPathname;
5 changes: 2 additions & 3 deletions src/ui/components/nav/components/NavLink.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"use client";

import clsx from "clsx";
import { usePathname } from "next/navigation";
import { LinkWithChannel } from "@/ui/atoms/LinkWithChannel";
import useSelectedPathname from "@/hooks/useSelectedPathname";

export function NavLink({ href, children }: { href: string; children: JSX.Element | string }) {
const pathname = usePathname();

const pathname = useSelectedPathname();
const isActive = pathname === href;

return (
Expand Down

0 comments on commit c8a6537

Please sign in to comment.