š” Key Takeaways
ā” Project Setup: Use create-next-app with TypeScript or JavaScript.
šļø App Structure: App Router (app/) for modern nested layouts; page.tsx per route.
š Routing: Pages map to URLs automatically; layouts wrap pages globally or nested.
š Dev & Prod: next dev for development, next build && next start for production.
š§© Best Practices: Global CSS in styles/, shared UI in layout.tsx.
1ļøā£ Create a New App
- Initialize with TypeScript or JavaScript
- Optionally add Tailwind CSS
- Choose App Router (modern) or Pages Router
npx create-next-app@latest my-app
# TypeScript version
npx create-next-app@latest my-app --typescript
2ļøā£ Start the Dev Server
- Navigate to project folder
- Run dev server on
http://localhost:3000
cd my-app
npm run dev
# or
yarn dev
3ļøā£ Folder Structure (App Router)
app/ā pages and layoutspublic/ā static assetsstyles/ā global CSS or Tailwind filesnext.config.jsā project configuration
my-app/
āāā app/
ā āāā page.tsx # Home page
ā āāā layout.tsx # Root layout
ā āāā about/page.tsx # Nested route
āāā public/
āāā styles/
āāā next.config.js
4ļøā£ Add a New Route
- Create a folder under
app/for route - Add
page.tsxfor the route component
// app/about/page.tsx
export default function About() {
return <h1>About Page</h1>;
}
// Accessible at /about
5ļøā£ Add a Global Layout
- Wrap pages with shared UI like header/footer
- Layouts support nested routes
// app/layout.tsx
export default function RootLayout({ children }) {
return (
<html>
<body>{children}</body>
</html>
);
}
6ļøā£ Build and Start Production
- Create production-ready build
- Start server to serve optimized pages
npm run build
npm run start
7ļøā£ Quick Tips
- Use
next devfor development - Place global CSS in
app/styles/globals.css - Use
page.tsxfor individual routes - Prefer App Router for server components and nested layouts