- Minimum Node.js version updated from 16.14 to 18.17 since 16.x is now out-of-support.
- Use the command
npx create-next-app@latest appName
to create a new Next.js application.
- app folder: Main working area, handling routes, layouts, and loading states.
- node_modules: Contains project dependencies.
- public: For static assets.
- .gitignore: Specifies files ignored by source control.
- package.json: Look at scripts, use
npm run dev
to start the project.
page.tsx
in the root of the app folder represents the root of the application.- It's a React component acting as the main page.
- Create folders and
page.js
files inside the app folder for new pages (e.g.,about/page.js
orcontact/page.js
).
- Use the Link component to navigate around the project.
- Create nested routes like
app/info/contact/page.tsx
. Missingpage.tsx
will result in a 404 error.
- Use vanilla CSS in
globals.css
and consider using TailwindCSS.
layout.tsx
: Wraps other pages and layouts to share UI. Does not re-render when the route changes.- Templates are similar but do re-render.
- Create a
Navbar.tsx
component and render it inlayout.tsx
.
- Automatically self-host Google Fonts. They're included in your deployment and served from the same domain.
- Define your application metadata using Next.js's Metadata API for better SEO and shareability.
- Server Components: Default in Next.js, great for data fetching, security, caching, and reducing bundle size.
- Client Components: Useful for interactivity, state management, and using browser APIs.
- Use async functions to fetch data in server components.
- Use
loading.js
to show a loading UI with React Suspense while content loads.
- Use
error.tsx
to handle unexpected runtime errors in nested routes.
- Create nested layouts within specific route segments using
layout.tsx
.
- Create dynamic routes like
app/tours/[id]/page.tsx
to handle parameterized paths.
- Use the Link component to set up navigation links in dynamic routes.
- The Next.js Image component optimizes images for size, stability, and faster page loads. It supports both local and remote images.
- Use the
fill
prop for responsive images and thesizes
property to improve performance based on the user's device and screen size.