11import type { ReactNode } from "react" ;
22import { cn } from "@/lib/utils" ;
3- import { usePathname } from "next/navigation" ;
43
54export interface StackNavigationItem {
65 name : string ;
@@ -27,16 +26,24 @@ export interface StackNavigationProps {
2726 header ?: ReactNode ;
2827 footer ?: ReactNode ;
2928 orientation ?: "vertical" | "horizontal" ;
29+ /**
30+ * For framework-specific routers, user can pass the pathname from their hooks:
31+ * - TanStack Router: `useLocation().pathname`
32+ * - React Router: `useLocation().pathname`
33+ * - Next.js: `usePathname()`
34+ */
35+ pathname ?: string ;
3036}
3137
3238function DefaultNavItem ( {
3339 item,
3440 orientation = "vertical" ,
41+ pathname,
3542} : {
3643 item : StackNavigationItem ;
3744 orientation ?: "vertical" | "horizontal" ;
45+ pathname : string ;
3846} ) {
39- const pathname = usePathname ( ) ;
4047 const isActive = pathname === item . path ;
4148
4249 const isHorizontal = orientation === "horizontal" ;
@@ -126,7 +133,10 @@ export function StackNavigation({
126133 header,
127134 footer,
128135 orientation = "vertical" ,
136+ pathname : providedPathname ,
129137} : StackNavigationProps ) {
138+ // Use provided pathname or fall back to window.location.pathname
139+ const pathname = providedPathname ?? ( typeof window !== "undefined" ? window . location . pathname : "" ) ;
130140 const isHorizontal = orientation === "horizontal" ;
131141
132142 return (
@@ -183,7 +193,7 @@ export function StackNavigation({
183193 { renderItem ? (
184194 renderItem ( navItem )
185195 ) : (
186- < DefaultNavItem item = { navItem } orientation = { orientation } />
196+ < DefaultNavItem item = { navItem } orientation = { orientation } pathname = { pathname } />
187197 ) }
188198 </ div >
189199 ) ;
0 commit comments