Skip to content

Commit a676468

Browse files
1.4 CSS Modules
1 parent 24b68d7 commit a676468

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

components/NavBar.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
import Link from "next/link";
22
import { useRouter } from "next/router";
3+
import styles from "./NavBar.module.css";
34

45
export default function NavBar() {
56
const router = useRouter();
67
return (
78
<nav>
89
<Link href="/">
9-
<a style={{ color: router.pathname === "/" ? "red" : "blue" }}>Home</a>
10+
<a
11+
className={`${styles.link} ${
12+
router.pathname === "/" ? styles.active : ""
13+
}`}
14+
>
15+
Home
16+
</a>
1017
</Link>
1118
<Link href="/about">
12-
<a style={{ color: router.pathname === "/about" ? "red" : "blue" }}>
19+
<a
20+
className={[
21+
styles.link,
22+
router.pathname === "/about" ? styles.active : "",
23+
].join(" ")}
24+
>
1325
About
1426
</a>
1527
</Link>

components/NavBar.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.link {
2+
text-decoration: none;
3+
}
4+
5+
.active {
6+
color: tomato;
7+
}

0 commit comments

Comments
 (0)