Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

Why Your Next.js Modal Route Works Until Someone Refreshes the Page

A Next.js modal route needs a normal page for direct visits and refreshes. Learn how soft navigation, parallel-slot fallbacks, and interceptor segment counts fit together.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A modal route should have two valid presentations: a contextual modal when reached through in-app navigation, and a normal page when someone opens its URL directly or refreshes. The failure usually comes from treating the modal presentation as the route itself. Next.js can preserve parallel-slot state during a soft navigation, but a full-page load must recover the route without that earlier client state.

Why a refresh changes what Next.js can render

In the App Router, an intercepted route lets a destination appear in context—for example, a photo displayed in a modal over a gallery. During client-side, or soft, navigation, Next.js can retain the active subpage in parallel route slots. The URL changes, but the app can preserve the surrounding page.

As an Amazon Associate I earn from qualifying purchases.

A refresh or direct URL visit is a hard navigation: the browser loads the URL as a new page. Next.js cannot infer the active state of unmatched parallel slots from the previous client session. The contextual modal is therefore not a substitute for a regular page at that URL. The intended pattern is a modal during in-app navigation and a standalone page on direct access or refresh, as shown in the Next.js Intercepting Routes documentation.

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

Give the URL a normal page as well as a modal presentation

Keep a canonical page route for the content, then use an intercepted route to render that same destination in context when navigation originates inside the app. In the official photo example, clicking a photo in the gallery opens a modal; following its shareable URL or refreshing renders the full photo page.

This distinction makes the route usable beyond the original interaction. A user can share the URL, bookmark it, or arrive from another site without depending on a gallery page that may not exist in the current navigation state.

Add fallbacks for unmatched parallel slots

At the relevant layout level, inspect every parallel route slot. On a hard navigation, a slot may not match the URL, so Next.js needs a fallback. Add a default.js file for each slot that can be unmatched. The fallback should reflect the intended experience: return null when the slot should be empty, or use a not-found response when an unmatched slot should remain a 404. The Parallel Routes documentation describes slot state and fallbacks; the default.js reference covers the fallback convention.

Remember that the implicit children slot can also need a default.js. If Next.js cannot recover its parent page state on a hard navigation, a missing fallback there may be the problem even when the named modal slot has one. See the Missing Required default.js for Parallel Route guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check the interceptor against URL segments, not folder depth

Interception markers are counted against URL route segments. A parallel slot folder such as @modal does not add a segment to that count, even though it appears in the filesystem.

Matcher Meaning
(.) Intercept at the same route-segment level
(..) Intercept one route segment up
(..)(..) Intercept two route segments up
(...) Intercept from the app root

Count URL segments in the route hierarchy and ignore @slot folders. The matcher definitions and examples are in the Intercepting Routes reference.

Troubleshoot the failure in this order

  1. Test a fresh load. Open the failing URL in a new tab, then refresh it. Decide whether the expected result is a standalone page or a modal over a meaningful base page. The documented photo pattern uses the standalone page for direct access and refresh.
  2. Confirm both route presentations exist. Verify that the URL has a normal page route as well as the intercepted route used for contextual navigation.
  3. Audit fallbacks at the layout level. Check every potentially unmatched parallel slot, including children. Add default.js where needed, and choose null or not-found behavior according to the intended UX.
  4. Recount the matcher. Count URL route segments rather than filesystem folders, and do not count @modal or another slot folder as a segment.
  5. Test browser history separately. Use back to close the modal and forward to reopen it, then test refresh independently. Back/forward navigation and a new full-page load do not have the same slot-state recovery conditions.
  6. If the structure matches the documented pattern, collect specifics. Record the folder tree, exact Next.js version, failing URL, runtime or build error, and deployment environment before attributing the problem to a version issue, deployment setting, or cache behavior.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.