LESSON 02 / 03

Pages, Layouts & Links

Folders become URLs, layouts wrap pages and stay mounted while you navigate, and Link makes page changes instant.

๐ŸŽ“Mediumlevel
โฑ๏ธ35 minto finish
โœ๏ธ1activities

๐Ÿ“‚ Next.js Foundations๐Ÿท๏ธ Next.js

๐ŸŽฏ By the end of this lesson you canโ€ฆ

  • Create pages and nested routes
  • Share UI with layouts
  • Navigate with Link
โš›๏ธ JSX app/layout.jsx ๐Ÿ‘† Tap a line to explain it
1import "./globals.css";2import Link from "next/link";3 4export const metadata = { title: "My Notes", description: "Notes that think with you" };5 6export default function RootLayout({ children }) {7  return (8    <html lang="en">9      <body>10        <nav>11          <Link href="/">Home</Link> ยท <Link href="/notes">Notes</Link> ยท <Link href="/about">About</Link>12        </nav>13        <main>{children}</main>14      </body>15    </html>16  );17}
โš›๏ธ JSX app/about/page.jsx
1export default function AboutPage() {2  return <h1>About this app</h1>;3}

The same idea, simulated in a live React preview โ€” click the links and notice the navigation bar never disappears:

โš›๏ธ React App.jsx
1function Layout({ children, go }) {2  return (3    <div style={{ fontFamily: "system-ui" }}>4      <nav style={{ display: "flex", gap: 12, padding: 10, background: "#1f2544", borderRadius: 12 }}>5        {["/", "/notes", "/about"].map((href) => <a key={href} href="#" onClick={(e) => { e.preventDefault(); go(href); }} style={{ color: "#ffd166" }}>{href}</a>)}6      </nav>7      <main style={{ padding: 10 }}>{children}</main>8    </div>9  );10}11const pages = { "/": <h2>๐Ÿ  Home</h2>, "/notes": <h2>๐Ÿ“ Notes</h2>, "/about": <h2>๐Ÿ‘‹ About</h2> };12function App() {13  const [path, setPath] = useState("/");14  return <Layout go={setPath}>{pages[path]}</Layout>;15}
๐Ÿ’ก Concept check
Why use <Link> instead of <a> for internal pages?

๐Ÿ“Œ Key takeaways

  • app/blog/page.jsx โ†’ /blog.
  • layout.jsx wraps every page below it and keeps its state between navigations.
  • <Link href="/about"> navigates without a full page reload.

Finished reading & practising?

Saved in this browser. Create a free account to keep it forever.