Question presented to candidate:
"In our photo feed, clicking a photo should open it in a modal over the feed, but the URL must change to /photo/123 so it can be shared, and opening that link directly should show a normal photo page. How do you build that in the App Router?"
What a strong answer should cover:
- An intercepting route loads another route inside the current layout during a client navigation, while the URL changes to the real address.
- Matchers in the folder name:
(.)same level,(..)one level up,(..)(..)two levels up,(...)from the app root; they count route segments, not folders, so@slotand group folders do not count. - Interception only happens on soft navigation from inside the app. A reload, a direct visit or a shared link renders the real page.
- The modal pattern combines it with a parallel route:
@modal/(.)photo/[id]/page.tsx, plus@modal/default.tsxreturningnull. - Closing:
router.back(), or a Link to a URL where the slot matches something that returnsnull(for example a catch-all in the slot). - The server decides interception from the
Next-Urlrequest header (the page the user is on), and the response varies on it.
Clarifying questions expected:
- "Should a refresh keep the modal open?" β with interception it shows the full page instead; that is the intended behaviour.
- "Where can the modal be opened from?" β decides the level of the matcher and where the slot lives.
Code / implementation expected: Yes β a feed layout with an @modal slot, an intercepted (.)photo/[id] page, the real photo/[id] page and a client Modal that closes with router.back().