Challenge - 5 Problems
Canonical URL Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What is the rendered output of this Next.js component?
Consider this Next.js component that sets a canonical URL in the head. What will be the exact tag rendered inside the ?
NextJS
import Head from 'next/head'; export default function Page() { return ( <> <Head> <link rel="canonical" href="https://example.com/page" /> </Head> <main> <h1>Page Content</h1> </main> </> ); }
Attempts:
2 left
💡 Hint
Look at the href attribute inside the tag in the Head component.
✗ Incorrect
The component explicitly sets the canonical URL to 'https://example.com/page' inside the Head component, so the rendered tag will have that exact href.
📝 Syntax
intermediate1:30remaining
Which option correctly sets a canonical URL in Next.js using the Head component?
You want to add a canonical URL to your Next.js page. Which code snippet correctly sets it?
Attempts:
2 left
💡 Hint
Remember the correct React component and attribute names.
✗ Incorrect
Next.js uses the Head component imported from 'next/head' to add elements to the HTML head. The correct tag for canonical URLs is .
❓ state_output
advanced2:00remaining
What is the canonical URL after this dynamic Next.js page renders?
Given this dynamic Next.js page that sets the canonical URL based on props, what is the canonical URL in the rendered HTML if the prop slug is 'blog-post'?
NextJS
import Head from 'next/head'; export default function Post({ slug }) { const canonicalUrl = `https://example.com/${slug}`; return ( <> <Head> <link rel="canonical" href={canonicalUrl} /> </Head> <article> <h1>Post: {slug}</h1> </article> </> ); }
Attempts:
2 left
💡 Hint
Check how the canonicalUrl variable is constructed using the slug prop.
✗ Incorrect
The canonicalUrl is built by combining the base URL 'https://example.com/' with the slug prop 'blog-post', resulting in 'https://example.com/blog-post'.
🔧 Debug
advanced2:00remaining
Why does this Next.js page fail to set the canonical URL correctly?
This Next.js page tries to set a canonical URL but it does not appear in the page source. What is the cause?
NextJS
import Head from 'next/head'; export default function Page() { return ( <> <head> <link rel="canonical" href="https://example.com/page" /> </head> <main> <h1>Page Content</h1> </main> </> ); }
Attempts:
2 left
💡 Hint
Check the difference between HTML and Next.js Head component.
✗ Incorrect
Next.js requires using the imported Head component from 'next/head' to modify the document head. Using lowercase is ignored by React and does not inject tags into the HTML head.
🧠 Conceptual
expert1:30remaining
Why is setting a canonical URL important in Next.js SEO?
Which of the following best explains why you should set canonical URLs in your Next.js pages?
Attempts:
2 left
💡 Hint
Think about SEO and duplicate content issues.
✗ Incorrect
Canonical URLs inform search engines which URL is the main one when multiple URLs have similar content, preventing duplicate content penalties and improving SEO.