Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

Next.js Parallel and Intercepting Routes: Build Modals That Work

Use a parallel route slot and an intercepted route to show a shareable destination as a modal during client navigation and as a full page on direct visits.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a parallel route slot and an intercepted route to show a destination such as /login in a modal during client-side navigation, while keeping that same URL usable as a full page when opened directly or refreshed. The key is to define both route states, provide an explicit default.tsx fallback for the slot, and choose a close behavior that matches how the modal was opened.

How parallel and intercepting routes work together

A parallel route is a named slot rendered by a shared layout. A folder such as @auth supplies an auth prop to that layout; the slot name does not become part of the URL. The implicit children prop is another slot. The layout can render the normal page and the modal slot together. Next.js documentation on Parallel Routes

As an Amazon Associate I earn from qualifying purchases.

An intercepting route lets a destination render within the current layout during client-side navigation. For example, a link to /login can update the browser URL to /login while displaying login content in an overlay. Opening or refreshing /login directly instead renders the standalone login page. Next.js documentation on Intercepting Routes

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set up the routes and fallback

This minimal structure uses a shared login-content component so both route presentations show the same form:

app/
  layout.tsx
  login/
    page.tsx
  @auth/
    default.tsx
    (.)login/
      page.tsx

The root layout renders both slots:

// app/layout.tsx
export default function RootLayout({
  children,
  auth,
}: {
  children: React.ReactNode
  auth: React.ReactNode
}) {
  return (
    <html lang="en">
      <body>
        {children}
        {auth}
      </body>
    </html>
  )
}

Use a shared content component rather than putting modal behavior into the form itself. That lets the content remain a Server Component if it does not need client-side behavior.

// app/login/page.tsx
import LoginContent from "@/components/login-content"

export default function LoginPage() {
  return <LoginContent />
}

The intercepted route wraps the same content in your modal component:

// app/@auth/(.)login/page.tsx
import LoginContent from "@/components/login-content"
import Modal from "@/components/modal"

export default function LoginModal() {
  return (
    <Modal>
      <LoginContent />
    </Modal>
  )
}

For the slot’s unmatched hard-load fallback, return null:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
// app/@auth/default.tsx
export default function DefaultAuth() {
  return null
}

In Next.js 16, every parallel route slot requires an explicit default.js file; the upgrade guide says builds fail without these defaults. Keep the fallback even if the slot is usually empty. Confirm the requirement against the version installed in your app. Next.js 16 upgrade guide Next.js documentation on default.js

Choose the interception matcher by route depth

The matcher counts URL route segments, not every directory in the filesystem. In particular, a named slot such as @auth is not a route segment. That is why the example uses (.)login even though the intercepted route lives inside the @auth directory. Next.js documentation on Intercepting Routes

  • (.) matches at the same route-segment level.
  • (..) matches one route segment up.
  • (..)(..) matches two route segments up.
  • (...) matches from the app root.

Work out the URL segment relationship between the route where navigation starts and the destination, then select the matcher. Do not count route groups, slots, or physical folders as URL segments unless they actually create a route segment.

What changes on navigation, refresh, and back

During soft navigation, Next.js partially renders the changed slot and can preserve active subpages in other slots even when those subpages do not match the new URL. On a hard navigation or refresh, it cannot recover unmatched slot state, so it uses the slot’s default.js fallback. If a required fallback is missing, the result can be an error or 404 depending on the route and framework version. Next.js documentation on Parallel Routes Next.js guidance for a missing parallel-route default

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For the login example, the intended states are:

  • Navigate from another page using a client-side link to /login: the intercepted route shows the modal and the URL becomes /login.
  • Load or refresh /login directly: the full-page route renders.
  • Load another URL that has no active auth-slot route: the slot’s default returns null on a hard load.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make dismissal predictable

Choose a close action based on the navigation history and the state of the slot. Do not rely on an unmatched slot disappearing automatically during soft navigation.

Use browser history when there is a meaningful previous state

If the user opened the modal from a page they should return to, a client-side close button can call router.back(). This follows the same history entry created by opening the destination, so the underlying page reappears. It is a poor fit when users can arrive at the modal URL without a meaningful prior in-app page.

Navigate to a route that clears the slot

Another option is a link to a route handled in the modal slot by a page that returns null. This explicitly clears the slot rather than asking the browser to infer which page to restore.

Clear the slot for other destinations

If users can navigate elsewhere while the modal slot remains active, add an appropriate catch-all route in that slot that returns null. Next.js documents this pattern for clearing a slot on navigation to other paths. Test the routes your app supports so the catch-all does not conflict with a more specific slot route. Next.js documentation on Parallel Routes

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Decide when this pattern is appropriate

Use interception when the destination needs a real, shareable URL and users benefit from seeing it without losing the current page context. Next.js documents examples such as opening a photo from a feed, showing login from a navbar, or displaying a shopping cart in a side modal. Next.js documentation on Intercepting Routes

  • Standalone destination: implement a full-page route when direct visits and refreshes must show the destination independently of the page that opened it.
  • Preserved context: add interception when opening the destination should retain the visible page beneath an overlay.
  • Navigation semantics: decide whether close should return through browser history or explicitly navigate to a state that clears the slot.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.