Challenge - 5 Problems
Dynamic Route Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Remix route component render?
Given a dynamic route file named
routes/posts/$postId.jsx in Remix, what will the component render if the URL is /posts/42?Remix
import { useParams } from '@remix-run/react'; export default function Post() { const params = useParams(); return <div>Post ID is {params.postId}</div>; }
Attempts:
2 left
💡 Hint
Remember that dynamic route parameters are available via useParams hook.
✗ Incorrect
The dynamic segment
$postId captures the URL part '42'. The useParams hook returns an object with keys matching dynamic segments, so params.postId is '42'.📝 Syntax
intermediate1:30remaining
Which route file name correctly defines a dynamic parameter for user ID?
In Remix, which file name correctly creates a route with a dynamic parameter named
userId?Attempts:
2 left
💡 Hint
Remix uses a special prefix for dynamic segments in file names.
✗ Incorrect
Remix uses the
$ prefix to mark dynamic route segments. So $userId.jsx defines a dynamic parameter named userId.❓ state_output
advanced2:30remaining
What is the value of params in nested dynamic routes?
Consider the nested route files
routes/blog/$category/$postId.jsx. If the URL is /blog/tech/123, what is the value of params from useParams() inside the component?Remix
import { useParams } from '@remix-run/react'; export default function Post() { const params = useParams(); return <div>{JSON.stringify(params)}</div>; }
Attempts:
2 left
💡 Hint
All dynamic segments in the route path are included in params.
✗ Incorrect
The params object includes all dynamic segments from the route path. Here, category is 'tech' and postId is '123'.
🔧 Debug
advanced2:30remaining
Why does this dynamic route component fail to get the parameter?
Given the route file
routes/products/$productId.jsx and this component code, why does params.productId return undefined?Remix
import { useParams } from '@remix-run/react'; export default function Product() { const params = useParams; return <div>Product: {params.productId}</div>; }
Attempts:
2 left
💡 Hint
Check how useParams is used in the code.
✗ Incorrect
The code assigns useParams without calling it. It should be const params = useParams(); to get the params object.
🧠 Conceptual
expert3:00remaining
How does Remix handle optional dynamic route parameters?
Which statement correctly describes how Remix supports optional dynamic route parameters in file naming and routing?
Attempts:
2 left
💡 Hint
Think about how Remix routing matches files to URLs.
✗ Incorrect
Remix routing does not have built-in syntax for optional dynamic parameters. You create separate routes for the optional and non-optional cases.