Complete the code to create a basic page component in the Next.js App Router.
export default function Home() {
return <[1]>Hello, Next.js App Router!</[1]>;
}span which is less common for main containers.The div element is a common container for page content in React components.
Complete the code to export a page component as a React Server Component in Next.js App Router.
export default async function Page() {
const data = await fetch('/api/data');
const json = await data.json();
return <pre>{JSON.stringify([1], null, 2)}</pre>;
}The variable json holds the parsed JSON data to display.
Fix the error in the Next.js App Router page component by completing the import statement.
import [1] from 'next/navigation'; export default function Page() { const router = useRouter(); return <button onClick={() => router.push('/about')}>Go to About</button>; }
The useRouter hook from next/navigation is used to navigate programmatically.
Fill both blanks to create a layout component that wraps page content in Next.js App Router.
export default function [1]({ children }) { return <[2]>{children}</[2]>; }
The layout component is conventionally named Layout and uses a div to wrap children.
Fill all three blanks to create a server action that updates data and redirects in Next.js App Router.
import { redirect } from 'next/navigation'; export async function [1](formData) { await updateData(formData.get('[2]')); [3]('/success'); }
The server action is named updateUser, it gets the username from form data, and calls redirect to navigate after update.