0
0
NextJSframework~20 mins

Matching paths with config in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Path Matcher Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered output when matching a dynamic route with config?

Given the Next.js route configuration and a dynamic path, what will the component render?

NextJS
export const dynamicParams = false;

export function generateStaticParams() {
  return [{ slug: 'hello' }, { slug: 'world' }];
}

export default function Page({ params }) {
  return <p>Slug is: {params.slug}</p>;
}
A<p>Slug is: hello</p> for any path, ignoring dynamic params
B<p>Slug is: hello</p> when path is /hello, and <p>Slug is: world</p> when path is /world
C404 error for any path because dynamicParams is false
D<p>Slug is: undefined</p> for any path
Attempts:
2 left
💡 Hint

Consider how generateStaticParams and dynamicParams affect static generation and matching.

📝 Syntax
intermediate
1:30remaining
Which config option correctly disables dynamic route matching in Next.js?

Choose the correct way to disable dynamic route matching in a Next.js route segment config.

Aexport const dynamicParams = false;
Bexport const dynamic = false;
Cexport const disableDynamic = true;
Dexport const staticParamsOnly = true;
Attempts:
2 left
💡 Hint

Check the official Next.js config option for dynamic route control.

state_output
advanced
2:00remaining
What is the output when using catch-all routes with config in Next.js?

Given this catch-all route and config, what will be the output for path /docs/intro/getting-started?

NextJS
export const dynamicParams = true;

export default function Page({ params }) {
  return <p>Docs path: {params.slug.join(' > ')}</p>;
}
A<p>Docs path: intro > getting-started</p>
B<p>Docs path: /docs/intro/getting-started</p>
C<p>Docs path: undefined</p>
D404 error because dynamicParams is true
Attempts:
2 left
💡 Hint

Remember how catch-all routes pass params as arrays and how dynamicParams affects matching.

🔧 Debug
advanced
2:30remaining
Why does this Next.js route always show 404 despite correct params?

Analyze the code and config below. Why does the route show 404 for path /product/123?

NextJS
export const dynamicParams = false;

export function generateStaticParams() {
  return [{ id: '456' }];
}

export default function Page({ params }) {
  return <p>Product ID: {params.id}</p>;
}
ABecause dynamicParams must be true to use generateStaticParams
BBecause params.id is undefined in the component
CBecause generateStaticParams does not include '123', so path is not pre-rendered and dynamicParams is false
DBecause generateStaticParams returns wrong key name; it should be 'slug' not 'id'
Attempts:
2 left
💡 Hint

Check the interaction between dynamicParams and generateStaticParams.

🧠 Conceptual
expert
3:00remaining
How does Next.js decide which paths to match when dynamicParams is false and generateStaticParams returns multiple entries?

Explain the matching behavior of Next.js routes when dynamicParams = false and generateStaticParams returns multiple paths. Which paths are served and which cause 404?

ANext.js serves all paths dynamically regardless of generateStaticParams when dynamicParams is false
BAll paths matching the route pattern are served, but those not in generateStaticParams show fallback content
COnly the first path returned by generateStaticParams is served; others cause 404
DOnly the paths returned by generateStaticParams are served; all others cause 404 because dynamic matching is disabled
Attempts:
2 left
💡 Hint

Think about static generation and disabling dynamic routes.