Przegląd stron i layoutów
Poznaj różnicę między stronami a layoutami oraz dowiedz się, jak łączą się one w strukturę interfejsu użytkownika aplikacji Next.js
Przegląd stron i layoutów to bezpłatna lekcja Next.js 15 Fullstack (App Router + Server Actions) na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Next.js 15 Fullstack (App Router + Server Actions), a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Next.js 15 Fullstack (App Router + Server Actions) zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
Welcome to Pages & Layouts
Next.js UI rests on two ideas: Pages and Layouts. This lesson shows what each one is and how they combine to build your interface.
What is a Page?
A Page is a React component that renders the UI for one route. Default-export it from a page.js file and that route gets its own view.
Creating a Simple Page
Here's a basic page.js that renders the home route /. A page is just a default-exported component — nothing more.
// app/page.js
export default function HomePage() {
return (
<h1>Welcome to My App!</h1>
);
}What is a Layout?
A Layout is UI shared across pages — a wrapper that gives consistent structure. Export it from layout.js; it takes a children prop for nested content.
The Root Layout
Every App Router app needs a root layout at app/layout.js. It wraps the whole app, including the html and body tags — the place for global styles and metadata.
// app/layout.js
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
{children}
</body>
</html>
);
}Nested Layouts
Add a layout.js inside any folder for a nested layout. An app/dashboard/layout.js wraps every page under dashboard — unique shared UI per section.
How They Combine
Next.js nests layouts automatically: a page renders inside its parent layout's children, that inside its parent's, all the way up to the root.
Example: A Blog Section
Picture a blog: blog/layout.js gives a shared nav, blog/page.js is the index, and blog/first-post/page.js a post — each nesting upward into the root.
Code: Blog Layout Example
This blog/layout.js wraps every /blog page with a header, nav, and footer — shared chrome that stays consistent across the section.
// app/blog/layout.js
export default function BlogLayout({ children }) {
return (
<div>
<header><h1>My Awesome Blog</h1></header>
<nav>
<a href="/blog">Home</a> | <a href="/blog/archive">Archive</a>
</nav>
<main>{children}</main>
<footer><p>© 2023 CoddyKit Blog</p></footer>
</div>
);
}Code: Blog Page Example
And here's blog/page.js. Its content renders right where {children} sits inside BlogLayout — page slotting into layout.
// app/blog/page.js
export default function BlogHomePage() {
return (
<section>
<h2>Welcome to the Blog Homepage!</h2>
<p>Discover our latest articles and insights.</p>
</section>
);
}Pages vs. Layouts Quiz
Let's check your understanding of Next.js pages and layouts.
Recap: Pages & Layouts
Recap: Pages (page.js) render a route's unique UI, Layouts (layout.js) share UI across routes, and Next.js nests them via children.
Często zadawane pytania
Czy lekcja „Przegląd stron i layoutów” jest bezpłatna?
Tak — pełny tekst „Przegląd stron i layoutów” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Next.js 15 Fullstack (App Router + Server Actions), przejdź na CoddyKit PRO. Kurs Next.js 15 Fullstack (App Router + Server Actions) zawiera 4 lekcji w sumie.
Co nauczysz się w „Przegląd stron i layoutów”?
Poznaj różnicę między stronami a layoutami oraz dowiedz się, jak łączą się one w strukturę interfejsu użytkownika aplikacji Next.js Ćwiczysz Next.js 15 Fullstack (App Router + Server Actions) z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Next.js 15 Fullstack (App Router + Server Actions)?
Nie wymagamy żadnego doświadczenia. Next.js 15 Fullstack (App Router + Server Actions) w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.
Ile czasu zajmuje lekcja „Przegląd stron i layoutów”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Next.js 15 Fullstack (App Router + Server Actions)?
Tak. Każda lekcja Next.js 15 Fullstack (App Router + Server Actions) zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Konfiguracja projektu i CLI
- Podstawy routingu opartego na systemie plików
- Przegląd stron i layoutów
- Stylowanie aplikacji Next.js