Skip to content

Commit 463792d

Browse files
committed
fix active tab
1 parent 179c6ca commit 463792d

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

apps/create-hypergraph/template-vite-react/src/components/explore-tabs.tsx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link, useRouter } from '@tanstack/react-router';
1+
import { Link } from '@tanstack/react-router';
22
import { clsx } from 'clsx';
33

44
type Tab = {
@@ -14,29 +14,22 @@ const tabs: Tab[] = [
1414
];
1515

1616
export function ExploreTabs() {
17-
const router = useRouter();
18-
const pathname = router.state.location.pathname ?? '';
19-
2017
return (
2118
<div className="w-full flex justify-center">
2219
<div className="inline-flex rounded-lg border bg-background p-1">
23-
{tabs.map((tab) => {
24-
const isActive = pathname.startsWith(tab.to);
25-
return (
26-
<Link
27-
key={tab.to}
28-
to={tab.to}
29-
className={clsx(
30-
'px-4 py-2 text-sm rounded-md transition-colors',
31-
isActive
32-
? 'bg-primary text-primary-foreground'
33-
: 'text-foreground hover:bg-accent hover:text-accent-foreground',
34-
)}
35-
>
36-
{tab.label}
37-
</Link>
38-
);
39-
})}
20+
{tabs.map((tab) => (
21+
<Link
22+
key={tab.to}
23+
to={tab.to}
24+
activeOptions={{ exact: false }}
25+
activeProps={{ className: 'bg-primary text-primary-foreground' }}
26+
className={clsx(
27+
'px-4 py-2 text-sm rounded-md transition-colors text-foreground hover:bg-accent hover:text-accent-foreground',
28+
)}
29+
>
30+
{tab.label}
31+
</Link>
32+
))}
4033
</div>
4134
</div>
4235
);

0 commit comments

Comments
 (0)