Work & Development · Backend & Full Stack Development
Free preview
Create a Next.js 16 App Router project
Lesson 1 of Full Stack Applications with Next.js. Anyone can read this lesson with no account. Every lesson after this one is for students.
Routes and rendering
Create the journal project and learn which files make a page or a shared layout.
After this lesson you will have a Next.js 16 project with a home page and a journal section that share a layout, built from a reproducible setup.
What Next.js adds to React
First finish the React, TypeScript, Secure APIs, and Testing courses named in the course description. Full stack means connecting the browser interface, server work and data storage. Next.js helps build that connection with React.
Its App Router maps folders to web addresses, called routes. A file named page.tsx creates a page. A layout.tsx wraps the pages beneath it, like a shared frame around several pictures. Start with public placeholder text so you can check routing before adding private data.
Worked example: create the project
Use Node 22 or newer, in a folder outside any other project:
npx create-next-app@16.4.0 journal-practice --ts --eslint --app --src-dir --use-npm --no-tailwind --import-alias "@/*" --yes
cd journal-practice
npm ls next react
npm run dev -- --hostname 127.0.0.1
npm ls should show next@16.4.0 and react@19.3.0. Open http://127.0.0.1:3000.
Open next.config.ts. This template enables cacheComponents: true. Prerendering means preparing page content ahead of a request, often during the build. Next prepares what it can in advance.
Other work needs the current request, such as its cookies, route ID or database reads. Put that work inside <Suspense>. A Suspense boundary shows a fallback, such as "Loading," while that part is being prepared. Streaming means sending ready parts without waiting for every part to finish. You will use this pattern in the next lesson.
Replace src/app/page.tsx:
import Link from 'next/link';
export default function Home() {
return (
<main>
<h1>Journal practice</h1>
<ul>
<li><Link href="/journal">Open your journal</Link></li>
<li><Link href="/examples/n1">Read a public example</Link></li>
</ul>
</main>
);
}
Create src/app/journal/layout.tsx:
import Link from 'next/link';
export default function JournalLayout({ children }: { children: React.ReactNode }) {
return (
<main>
<h1>Learning journal</h1>
<nav aria-label="Journal">
<Link href="/">Home</Link>{' '}
<Link href="/journal">All entries</Link>
</nav>
{children}
</main>
);
}
And a first src/app/journal/page.tsx:
export default function JournalHome() {
return <section><h2>Your entries</h2><p>Entries will appear here.</p></section>;
}
Open the home page and follow Open your journal. You should see the shared Learning journal heading, the Home and All entries links, and the page's own Your entries section. The template's src/app/layout.tsx already provides <html> and <body>; never repeat those in a nested layout.
How routes map to files
| URL | File |
|---|---|
/ | src/app/page.tsx |
/journal | src/app/journal/page.tsx, inside src/app/journal/layout.tsx |
A folder without a page.tsx has no URL of its own.
Practice
- Add an
/aboutpage with a heading and a link back home. - Rename
src/app/journal/page.tsxtopages.tsx. Visit/journal: you get a 404, because onlypage.tsxcreates a route. Rename it back. - Commit the project and push it to a new private GitHub repository. Write the setup commands and versions in the README.
Check yourself
- Does every folder under
appcreate a page? - Why keep the root layout?
- What must wrap a component that reads cookies when Cache Components is on?
Answers
- No. Only a folder containing
page.tsxdoes. - It provides the document's
<html>and<body>, which every page needs. - A
<Suspense>boundary.
Next, you will add dynamic routes for public example entries.
Sources: Next.js installation, Layouts and pages.
Continue with the full course
This free preview is lesson 1 only. Enroll to open the rest of Full Stack Applications with Next.js.