Complete the code to create a Next.js page that sets a custom page title for SEO.
import Head from 'next/head'; export default function Home() { return ( <> <Head> <title>[1]</title> </Head> <main> <h1>Welcome to my site</h1> </main> </> ); }
The <title> tag inside Head sets the page title, which is important for SEO. Here, 'My Next.js SEO Page' is a meaningful title.
Complete the code to add a meta description tag for SEO in a Next.js page.
import Head from 'next/head'; export default function About() { return ( <> <Head> <meta name="description" content="[1]" /> </Head> <main> <h1>About Us</h1> </main> </> ); }
The meta description provides a summary for search engines. A clear, informative description like 'Learn more about our company and values.' helps SEO.
Fix the error in the Next.js page to ensure the meta viewport tag is correctly added for SEO and responsiveness.
import Head from 'next/head'; export default function Contact() { return ( <> <Head> <meta name="viewport" content=[1] /> </Head> <main> <h1>Contact Us</h1> </main> </> ); }
The content attribute value must be a string enclosed in double quotes inside JSX. So it should be "width=device-width, initial-scale=1".
Fill both blanks to create a Next.js page that uses server-side rendering to improve SEO by fetching data before rendering.
export async function getServerSideProps() {
const res = await fetch('[1]');
const data = await res.json();
return { props: { data: [2] } };
}
export default function Blog({ data }) {
return (
<main>
<h1>Blog Posts</h1>
<ul>
{data.map(post => (
<li key={post.id}>{post.title}</li>
))}
</ul>
</main>
);
}To fetch blog posts from an API, the URL is 'https://api.example.com/posts'. The fetched JSON is assigned to data and passed as props.
Fill all three blanks to add SEO-friendly Open Graph meta tags in a Next.js page.
import Head from 'next/head'; export default function Product() { return ( <> <Head> <meta property="og:title" content="[1]" /> <meta property="og:description" content="[2]" /> <meta property="og:image" content="[3]" /> </Head> <main> <h1>Product Details</h1> </main> </> ); }
Open Graph tags help social media show rich previews. Use a clear title, descriptive text, and a valid image URL.