Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
81 lines
2.7 KiB
Plaintext
81 lines
2.7 KiB
Plaintext
---
|
|
title: Missing Required default.js for Parallel Route
|
|
---
|
|
|
|
> Parallel route slots require a `default.js` file to serve as a fallback during navigation.
|
|
|
|
## Why This Error Occurred
|
|
|
|
You're using [parallel routes](https://nextjs.org/docs/app/api-reference/file-conventions/parallel-routes#defaultjs) in your Next.js application, but one of your parallel route slots is missing a required `default.js` file, which causes a build error.
|
|
|
|
When using parallel routes, Next.js needs to know what to render in each slot when:
|
|
|
|
- Navigating between pages that have different slot structures
|
|
- A slot doesn't match the current navigation (only during hard navigation)
|
|
- After a page refresh when Next.js cannot determine the active state for a slot
|
|
|
|
The `default.js` file serves as a fallback to render when Next.js cannot determine the active state of a slot based on the current URL. Without this file, the build will fail.
|
|
|
|
## Possible Ways to Fix It
|
|
|
|
Create a `default.js` (or `.jsx`, `.tsx`) file in the parallel route slot directory that's mentioned in the error message.
|
|
|
|
For example, if you have this structure where different slots have pages at different paths:
|
|
|
|
```
|
|
app/
|
|
├── layout.js
|
|
├── page.js
|
|
├── @team/
|
|
│ └── settings/
|
|
│ └── page.js
|
|
└── @analytics/
|
|
└── page.js
|
|
```
|
|
|
|
You need to add `default.js` files for each slot, excluding the children slot:
|
|
|
|
```
|
|
app/
|
|
├── layout.js
|
|
├── page.js
|
|
├── default.js // Optiona: add this (for children slot)
|
|
├── @team/
|
|
│ ├── default.js // Add this
|
|
│ └── settings/
|
|
│ └── page.js
|
|
└── @analytics/
|
|
├── default.js // Add this
|
|
└── page.js
|
|
```
|
|
|
|
Without the root `default.js`, navigating to `/settings` would result in a 404, even though `@team/settings/page.js` exists. The `default.js` in the root tells Next.js what to render in the children slot when there's no matching page at that path. It's not required as other named slots default files are, but it's good to add to help improve the experience for your applications.
|
|
|
|
### Example `default.js` file:
|
|
|
|
The simplest implementation returns `null` to render nothing:
|
|
|
|
```jsx filename="app/@analytics/default.js"
|
|
export default function Default() {
|
|
return null
|
|
}
|
|
```
|
|
|
|
You can also preserve the old behavior of returning a 404:
|
|
|
|
```jsx filename="app/@team/default.js"
|
|
import { notFound } from 'next/navigation'
|
|
|
|
export default function Default() {
|
|
notFound()
|
|
}
|
|
```
|
|
|
|
### When you need `default.js`
|
|
|
|
You need a `default.js` file for each parallel route slot (directories starting with `@`) at each route segment.
|
|
|
|
## Useful Links
|
|
|
|
- [Parallel Routes Documentation](https://nextjs.org/docs/app/api-reference/file-conventions/parallel-routes#defaultjs)
|