0
0
NextJSframework~20 mins

Modal pattern with intercepting routes in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Modal Mastery with Intercepting Routes
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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>
}
AThe Photo Gallery page remains visible with the PhotoModal displayed on top as a modal dialog.
BOnly the PhotoModal page content is shown, replacing the Photo Gallery page entirely.
CThe app throws a runtime error because intercepting routes cannot be nested under the same folder.
DThe URL does not change and the modal does not open.
Attempts:
2 left
💡 Hint
Think about how intercepting routes allow rendering a modal over the existing page without full navigation.
📝 Syntax
intermediate
1: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?
Aapp/dashboard/(modal)/page.tsx
Bapp/dashboard/(modal)/[id].tsx
Capp/dashboard/modal/page.tsx
Dapp/dashboard/(modal)/[id]/page.tsx
Attempts:
2 left
💡 Hint
Intercepting routes use parentheses and dynamic segments need a folder with page.tsx inside.
🔧 Debug
advanced
2: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?
AThe dynamic segment [productId] is missing from the URL.
BThe parent layout does not include a <code>modal</code> slot to render the intercepting route.
CThe modal page file is named incorrectly and should be <code>modal.tsx</code> instead of <code>page.tsx</code>.
DNext.js does not support intercepting routes with dynamic segments.
Attempts:
2 left
💡 Hint
Check if the parent layout has a place to render the modal content.
state_output
advanced
2: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?
AThe background page state resets to initial values when the modal route activates.
BThe background page component unmounts and loses its state when the modal opens.
CThe background page component remains mounted and its state is preserved while the modal is open.
DThe background page state is frozen and cannot update until the modal closes.
Attempts:
2 left
💡 Hint
Think about how intercepting routes overlay UI without full page navigation.
🧠 Conceptual
expert
3: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?
AIntercepting routes update the URL, enabling deep linking and browser navigation for modals.
BClient-side state toggles automatically update the URL without extra code.
CIntercepting routes prevent the modal from being accessible via keyboard navigation.
DClient-side state toggles allow modals to persist across page reloads without URL changes.
Attempts:
2 left
💡 Hint
Consider how URLs and browser history behave with each approach.