Skip to content

Commit 62be845

Browse files
feat: Add active link styling to header
Applies primary foreground color to header links when they are active or their child routes are active.
1 parent cf98392 commit 62be845

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

src/components/Header.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { Button } from "@/components/ui/button";
22
import { Github, Moon, Play, Sun } from "lucide-react";
33
import { useTheme } from "next-themes";
4-
import { Link, useNavigate } from "react-router-dom";
4+
import { Link, useNavigate, useLocation } from "react-router-dom";
55
import deviLogo from "@/assets/devitools-logo.png";
66

77
const Header = () => {
88
const { theme, setTheme } = useTheme();
99
const navigate = useNavigate();
10+
const location = useLocation();
11+
12+
const isActiveLink = (path: string) => {
13+
return location.pathname === path || location.pathname.startsWith(path + '/');
14+
};
1015

1116
const toggleTheme = () => {
1217
setTheme(theme === "dark" ? "light" : "dark");
@@ -32,23 +37,42 @@ const Header = () => {
3237
<nav className="hidden lg:flex items-center space-x-8">
3338
<Link
3439
to="/constructo"
35-
className="text-muted-foreground hover:text-primary transition-colors"
40+
className={`transition-colors hover:text-primary ${
41+
isActiveLink('/constructo')
42+
? 'text-primary'
43+
: 'text-muted-foreground'
44+
}`}
3645
>
3746
Constructo
3847
</Link>
3948
<Link
4049
to="/serendipity"
41-
className="text-muted-foreground hover:text-primary transition-colors"
50+
className={`transition-colors hover:text-primary ${
51+
isActiveLink('/serendipity')
52+
? 'text-primary'
53+
: 'text-muted-foreground'
54+
}`}
4255
>
4356
Serendipity
4457
</Link>
4558
<Link
4659
to="/effulgence"
47-
className="text-muted-foreground hover:text-primary transition-colors"
60+
className={`transition-colors hover:text-primary ${
61+
isActiveLink('/effulgence')
62+
? 'text-primary'
63+
: 'text-muted-foreground'
64+
}`}
4865
>
4966
Effulgence
5067
</Link>
51-
<Link to="/docs" className="text-muted-foreground hover:text-primary transition-colors">
68+
<Link
69+
to="/docs"
70+
className={`transition-colors hover:text-primary ${
71+
isActiveLink('/docs')
72+
? 'text-primary'
73+
: 'text-muted-foreground'
74+
}`}
75+
>
5276
Todas as Soluções
5377
</Link>
5478
</nav>

0 commit comments

Comments
 (0)