Table of Contents
Next.js is a framework for building web applications with React. React provides the component model. Next.js adds file-based routing, rendering options, and server endpoints, so a project can define pages and some backend behavior together.

App Router and Pages Router use different conventions
- App Router: A file such as
app/about/page.tsxcreates/about. Shared layouts uselayout.tsx, and HTTP endpoints use route handler files such asapp/api/hello/route.ts. App Router pages are Server Components by default. Use a Client Component for state, event handlers, or browser APIs. - Pages Router: A file such as
pages/about.tsxcreates the route. Existing projects may usegetStaticProps,getServerSideProps, andpages/api. Follow documentation for the router your code actually uses.

Next.js builds on React and supplies the application structure around it.
Choose how to render each type of page
Stable public pages can be prerendered and cached. A page that depends on the current request or a signed-in user may need server rendering at request time. Interactive controls can still run in the browser. Decide when data should refresh, and verify that private content cannot be served from a shared cache. Server-rendered HTML can help crawlers discover content, but indexing also depends on access, metadata, and the content itself.

Routing, rendering, and image handling are among the features Next.js adds to React.
Create and verify your first route
Install a Node.js version supported by the Next.js release you’re using. In a terminal, create a project and select the App Router if prompted.
npx create-next-app@latest my-next-app
cd my-next-app
npm run dev
Open http://localhost:3000. Add the following as app/about/page.tsx, or src/app/about/page.tsx if you selected a src directory.
export default function AboutPage() {
return <h1>About this project</h1>;
}
Visit http://localhost:3000/about and confirm the heading appears. Run npm run build before deploying. A static export supports a subset of features. Request-time rendering needs a compatible server or deployment platform. If components are new to you, start with the React Development course.

Reader Comments 0
Sign in with email or Google to join the discussion.