Challenge - 5 Problems
Modal Mastery with Intercepting Routes
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when you navigate to a modal route in Next.js intercepting routes?
Consider a Next.js app using intercepting routes to open a modal over the current page. What will the user see when navigating to
/photos/(modal)/123 if the modal route is set up correctly?NextJS
app/photos/page.tsx export default function PhotosPage() { return <div>Photo Gallery</div> } app/photos/(modal)/[id]/page.tsx export default function PhotoModal({ params }) { return <div role="dialog" aria-modal="true">Photo ID: {params.id}</div> }
Attempts:
2 left
💡 Hint
Think about how intercepting routes allow rendering a modal over the existing page without full navigation.
✗ Incorrect
In Next.js, intercepting routes like (modal) let you show a modal UI on top of the current page. The main page stays rendered, and the modal route renders inside the modal outlet. This keeps the background visible and accessible.
📝 Syntax
intermediate1:30remaining
Which code snippet correctly defines an intercepting route for a modal in Next.js?
You want to create a modal route under
/dashboard using intercepting routes. Which folder structure and file naming is correct?Attempts:
2 left
💡 Hint
Intercepting routes use parentheses and dynamic segments need a folder with page.tsx inside.
✗ Incorrect
Intercepting routes require parentheses around the segment name. Dynamic routes must be folders with a page.tsx file inside. So (modal)/[id]/page.tsx is correct.
🔧 Debug
advanced2:30remaining
Why does the modal not appear when navigating to the intercepting route?
Given this setup:
app/products/page.tsx
app/products/(modal)/[productId]/page.tsx
Navigating to
/products/(modal)/42 changes the URL but the modal does not show. What is the most likely cause?Attempts:
2 left
💡 Hint
Check if the parent layout has a place to render the modal content.
✗ Incorrect
For intercepting routes to render modals, the parent layout must include a
slot or children area where the modal route renders. Without it, the modal content won't appear.❓ state_output
advanced2:00remaining
What is the state of the background page when a modal intercepting route is open?
In a Next.js app using intercepting routes for modals, what happens to the React state of the background page when the modal route is active?
Attempts:
2 left
💡 Hint
Think about how intercepting routes overlay UI without full page navigation.
✗ Incorrect
Intercepting routes render the modal on top of the existing page without unmounting it. This means the background page stays mounted and its React state stays intact.
🧠 Conceptual
expert3:00remaining
Why use intercepting routes for modals instead of client-side state toggles in Next.js?
What is a key advantage of using Next.js intercepting routes for modals compared to managing modal visibility purely with React state?
Attempts:
2 left
💡 Hint
Consider how URLs and browser history behave with each approach.
✗ Incorrect
Using intercepting routes changes the URL to reflect the modal state, allowing users to bookmark or share links directly to modals and use browser back/forward buttons naturally.