Skip to content

Commit 24b68d7

Browse files
1.3 Routing
1 parent 51b7345 commit 24b68d7

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

components/NavBar.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Link from "next/link";
2+
import { useRouter } from "next/router";
3+
4+
export default function NavBar() {
5+
const router = useRouter();
6+
return (
7+
<nav>
8+
<Link href="/">
9+
<a style={{ color: router.pathname === "/" ? "red" : "blue" }}>Home</a>
10+
</Link>
11+
<Link href="/about">
12+
<a style={{ color: router.pathname === "/about" ? "red" : "blue" }}>
13+
About
14+
</a>
15+
</Link>
16+
</nav>
17+
);
18+
}

pages/about.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import NavBar from "../components/NavBar";
2+
13
export default function Potato() {
2-
return "about us";
4+
return (
5+
<div>
6+
<NavBar />
7+
<h1>About</h1>
8+
</div>
9+
);
310
}

pages/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { useState } from "react";
1+
import NavBar from "../components/NavBar";
22

33
export default function Home() {
4-
const [counter, setCounter] = useState(0);
54
return (
65
<div>
7-
<h1>Hello {counter}</h1>
8-
<button onClick={() => setCounter((prev) => prev + 1)}>+</button>
6+
<NavBar />
7+
<h1>Hello</h1>
98
</div>
109
);
1110
}

0 commit comments

Comments
 (0)