Clicking About opens a not-found screen.
Likely cause: The destination and folder path differ, or the page file is missing.
Check and correct: Check that the link is /about and the file is app/about/page.tsx, with a default component export.
PROJECT 1 · LESSON 2 OF 18
Build About and Contact routes without duplicating the navigation.
Continue from lesson 1: Create your first Next.js website. Keep existing files; create or replace the complete files listed below.
Extract the ZIP, open its project folder, and run npm install. Database lessons also need the .env.local setup described below. Checkpoints never contain credentials or node_modules.
Our site needs separate pages without three copies of the same header. This lesson makes the relationship between a URL, a folder and a layout explicit. The aim is to predict what Next.js will render before opening the browser.
A folder defines a URL segment; its page.tsx supplies the screen. A layout wraps all routes below it. The header belongs in the layout because every page needs it.
Link enables Next.js navigation. Ordinary anchors still work, but are useful for downloads and external sites rather than internal page transitions.
For /about, Next.js looks for the about route segment under app and its page.tsx. For /contact, it selects app/contact/page.tsx. The app folder itself is not part of the public URL. A normal helper file inside a folder does not create a page; the page convention does.
You can extend this rule: app/company/team/page.tsx corresponds to /company/team. Creating the company folder does not require creating a /company page. The parent can organize nested routes without displaying its own screen.
Link describes an internal destination and participates in Next.js navigation. On a client-side transition, Next.js updates the route content while preserving shared layouts. The browser address changes and Back/Forward remain useful. Directly visiting /about must also work; navigation is not limited to clicks from Home.
In production Next.js may prefetch eligible links, so a request can appear before you click. A full address-bar navigation and a Link transition can use different loading paths while reaching the same page. Do not infer the entire rendering model from one network entry.
About and Contact do not import the header. The root layout already wraps both. If you add a footer to the layout, both pages get it. If you add a paragraph inside About, only About changes. This gives you a simple test for placement: ask whether the content belongs to every route or just one.
The exported metadata object describes the page title and other document information. It does not render a visible heading. Your h1 and browser-tab title are separate outputs, and both should explain the current page. The contact link uses mailto because its destination is an email action, not a Next.js route.
Read this sequence before the source. Identify the input, the component or function that handles it, and the result the learner sees.
The user clicks the About Link.
Next.js resolves /about to app/about/page.tsx.
The root layout is shared with the previous route.
About content appears in the children position and the page metadata updates.
The paths below are relative to your practice project. Each block is the complete file at this checkpoint. Read its responsibility first, type or copy the code, then use the walkthrough to explain the important statements.
This is the page selected by the /about URL.
export const metadata = { title: "About EduShop" };
export default function About() {
return (
<>
<h1>About EduShop</h1>
<p>We sell practical learning supplies.</p>
</>
);
}
This gives /contact its own page content while reusing the shared layout.
export const metadata = { title: "Contact EduShop" };
export default function Contact() {
return (
<>
<h1>Contact us</h1>
<a href="mailto:hello@example.com">hello@example.com</a>
<p>This is a practice address; replace it before publishing.</p>
</>
);
}
Create app/company/team/page.tsx and visit /company/team. Then try /company.
The nested page can work while /company returns a not-found screen.
A folder establishes a segment; a page.tsx establishes a page at that segment. Nested pages do not automatically create parent pages.
A component named About does not create a route by itself. Its location must be app/about/page.tsx.
Likely cause: The destination and folder path differ, or the page file is missing.
Check and correct: Check that the link is /about and the file is app/about/page.tsx, with a default component export.
Likely cause: The page repeats navigation already supplied by the layout.
Check and correct: Keep shared navigation in layout.tsx and leave only the route content in the page.
Add /delivery with delivery information, then add its link to the root layout.
Attempt these questions before opening the explanations. Use the source above to justify your answer.
It integrates with Next.js client navigation and prefetching. It also produces a real navigable link rather than a click handler that merely changes visible state.
No. It is a normal module. That route would need app/about/card/page.tsx.