### Next.js Configuration with next.config.js Source: https://context7.com/hoangtannhut2209-glitch/tailieu/llms.txt Provides examples of configuring Next.js behavior using `next.config.js` or `next.config.ts`. Covers options like trailing slash, image optimization with remote patterns, redirects, and rewrites. ```typescript // next.config.ts import type { NextConfig } from "next"; const nextConfig: NextConfig = { /* config options here */ }; export default nextConfig; // next.config.js with advanced options /** @type {import('next').NextConfig} */ const nextConfig = { trailingSlash: true, images: { remotePatterns: [ { protocol: "http", hostname: process.env.NEXT_PUBLIC_WORDPRESS_API_HOSTNAME, port: "", }, ], }, }; module.exports = nextConfig; ``` -------------------------------- ### Next.js Link Component for Client-Side Navigation (TypeScript) Source: https://context7.com/hoangtannhut2209-glitch/tailieu/llms.txt Illustrates how to use the `next/link` component for client-side navigation and data fetching with `useSwr`. This example fetches user data and renders a list of links, each navigating to a user-specific page. It includes basic loading and error state handling. ```typescript // pages/index.tsx import type { User } from "../interfaces"; import useSwr from "swr"; import Link from "next/link"; const fetcher = (url: string) => fetch(url).then((res) => res.json()); export default function Index() { const { data, error, isLoading } = useSwr("/api/users", fetcher); if (error) return
Failed to load users
; if (isLoading) return
Loading...
; if (!data) return null; return ( ); } ``` -------------------------------- ### Next.js Form Component with Client-Side Navigation and Server Actions Source: https://context7.com/hoangtannhut2209-glitch/tailieu/llms.txt Utilize the `next/form` component for enhanced form handling with automatic client-side navigation. This example demonstrates creating a new post, persisting it using Prisma, and then redirecting the user while maintaining client state. ```typescript // app/posts/new/page.tsx import Form from "next/form"; import prisma from "@/lib/prisma"; import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; export default function NewPost() { async function createPost(formData: FormData) { "use server"; const title = formData.get("title") as string; const content = formData.get("content") as string; const authorEmail = (formData.get("authorEmail") as string) || undefined; const postData = authorEmail ? { title, content, author: { connect: { email: authorEmail } }, } : { title, content }; await prisma.post.create({ data: postData }); revalidatePath("/posts"); redirect("/posts"); } return (