The default.js Convention
The critical fallback for Parallel Routes on hard reload.
The parallel fallback
The default.js file is highly specialized: it is used *exclusively* in conjunction with Parallel Routes (slots named with an @ prefix, like @modal or @analytics).
It serves as a fallback UI for a parallel slot when Next.js doesn't know what else to render for that specific slot based on the current URL.
The hard reload problem
When a user navigates around your app using Next.js Links (client-side navigation), unmatched parallel slots simply remember and keep rendering whatever they were showing previously.
But if the user hits **Refresh** (a hard reload), the server must rebuild the page from scratch. The server has no memory of previous client state. If the current URL doesn't match any specific folder inside a parallel slot, Next.js panics and throws a 404 error.
Returning null
To fix this, you drop a default.js file into your slot folder (e.g., app/@modal/default.js).
When the server encounters an unmatched slot during a hard reload, it will render the default.js instead of throwing a 404. In many cases—especially for things like modals—your default.js will simply return null; to render nothing.
The Hard Reload Trap
Study the diagram. Notice how client-side navigation (clicking a Link) is perfectly safe, but hitting the Refresh button forces the server to rebuild. Without a default.js, the server panics and throws a 404.
Client Navigation
Using <Link>
/settings link@modal stateHard Reload
Browser Refresh
/settings@modal state. Must rebuild it from scratch.Parallel routes (like @modal) maintain their active state during normal client-side navigation. However, if a user hits Refresh, the server must reconstruct the entire page. If the current URL doesn't explicitly match a sub-route inside the @modal folder, Next.js requires a default.js file as a fallback, otherwise it throws a 404.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
default.jsis only used with Parallel Routes (slots).- It prevents 404 errors on hard reloads (page refreshes).
- It acts as a fallback when the current URL doesn't match a route inside the slot.
- For modals,
default.jsoften just returnsnull.
Done with this concept?
Mark it complete to track your progress. No login needed.