Pages and layouts
Next.js uses file-system based routing: folders and files in the app
directory define the routes of your site. A folder is a route segment that
maps to a URL segment, and a special file inside it renders the UI for that
segment.
A page is the UI for one route. Add a page file and default-export a React
component:
// app/page.tsx
export default function Page() {
return <h1>Hello Next.js!</h1>;
}
A layout is UI shared between multiple pages. Default-export a component
that accepts a children prop and render children where the page should
appear:
// app/layout.tsx
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
The layout at the root of app is the root layout. It is required, and
it must contain the <html> and <body> tags. On navigation, layouts preserve
their state, stay interactive, and do not rerender.
In short: folders define the routes, a page renders one route, and a layout
wraps pages with shared chrome.
You are about to answer a short quiz on file-system routing (page, layout).