Skip to the page

App Router foundations · senior

Parallel and intercepting routes (the modal pattern)

Parallel routes (@slot folders) render several pages in one layout; combined with intercepting routes ((.)photo/[id]) they give modals with a real, shareable URL that open on soft navigation and show the full page on refresh.

The notes

What you must know

  • A slot @modal is passed to the parent layout as a prop ({ children, modal }). Slots are not URL segments.
  • Soft navigation keeps each slot's active page even if it does not match the URL; a hard navigation (refresh) cannot recover it and renders default.tsx for unmatched slots, or a 404 if there is none.
  • Next.js 16 requires an explicit default.js for every parallel slot (the build fails without it); return null or call notFound().
  • Intercepting conventions: (.) same level, (..) one level up, (..)(..) two levels up, (...) from the app root.
  • Modal recipe: app/@modal/default.tsx returns null; app/@modal/(.)photo/[id]/page.tsx renders <Modal><Photo/></Modal>; app/photo/[id]/page.tsx is the full page for direct visits.
  • Close with router.back(); when navigating away with <Link>, match the slot to a page or catch-all that returns null.
  • Security: conditional slots (admin vs user) both render on the server; authorise inside each slot's page or the DAL.
  • Slots can have their own loading and error files and stream independently.

The red pen

Common traps: mistake → fix

  • Mistake: "Keep modal open state in client context"

    Fix: no shareable URL, Back does not close it.

  • Mistake: "Returning the admin slot only for admins protects it"

    Fix: both slots run and are sent; authorise in the slot.

  • Mistake: "default.js is optional"

    Fix: required for every slot in Next 16.

Easy to hard

Questions interviewers ask, easy to hard

  1. Build an Instagram-style photo modal with a shareable URL and a full page on refresh.
  2. What does (.)photo/[id] mean?
  3. What happens on refresh vs soft navigation?
  4. Why did the build fail after upgrading to Next 16?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview