Download next.js/docs/01-app/03-api-reference/03-file-conventions/default.mdx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.01 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/docs/01-app/03-api-reference/03-file-conventions/default.mdx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/docs/01-app/03-api-reference/03-file-conventions/default.mdx
-
curl -L -o default.mdx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/docs/01-app/03-api-reference/03-file-conventions/default.mdx
3.01 kB
| --- | |
| title: default.js | |
| description: API Reference for the default.js file. | |
| related: | |
| title: Learn more about Parallel Routes | |
| links: | |
| - app/api-reference/file-conventions/parallel-routes | |
| --- | |
| The `default.js` file is used to render a fallback within [Parallel Routes](/docs/app/api-reference/file-conventions/parallel-routes) when Next.js cannot recover a [slot's](/docs/app/api-reference/file-conventions/parallel-routes#slots) active state after a full-page load. | |
| During [soft navigation](/docs/app/getting-started/linking-and-navigating#client-side-transitions), Next.js keeps track of the active _state_ (subpage) for each slot. However, for hard navigations (full-page load), Next.js cannot recover the active state. In this case, a `default.js` file can be rendered for subpages that don't match the current URL. | |
| Consider the following folder structure. The `@team` slot has a `settings` page, but `@analytics` does not. | |
| <Image | |
| alt="Parallel Routes unmatched routes" | |
| srcLight="/docs/light/parallel-routes-unmatched-routes.png" | |
| srcDark="/docs/dark/parallel-routes-unmatched-routes.png" | |
| width="1600" | |
| height="930" | |
| /> | |
| When navigating to `/settings`, the `@team` slot will render the `settings` page while maintaining the currently active page for the `@analytics` slot. | |
| On refresh, Next.js will render a `default.js` for `@analytics`. If `default.js` doesn't exist, a `404` is rendered instead. | |
| Additionally, since `children` is an implicit slot, you also need to create a `default.js` file to render a fallback for `children` when Next.js cannot recover the active state of the parent page. | |
| ## Reference | |
| ### `params` (optional) | |
| A promise that resolves to an object containing the [dynamic route parameters](/docs/app/api-reference/file-conventions/dynamic-routes) from the root segment down to the slot's subpages. For example: | |
| ```tsx filename="app/[artist]/@sidebar/default.js" switcher | |
| export default async function Default({ | |
| params, | |
| }: { | |
| params: Promise<{ artist: string }> | |
| }) { | |
| const { artist } = await params | |
| } | |
| ``` | |
| ```jsx filename="app/[artist]/@sidebar/default.js" switcher | |
| export default async function Default({ params }) { | |
| const { artist } = await params | |
| } | |
| ``` | |
| | Example | URL | `params` | | |
| | ------------------------------------------ | ------------ | -------------------------------------------- | | |
| | `app/[artist]/@sidebar/default.js` | `/zack` | `Promise<{ artist: 'zack' }>` | | |
| | `app/[artist]/[album]/@sidebar/default.js` | `/zack/next` | `Promise<{ artist: 'zack', album: 'next' }>` | | |
| - Since the `params` prop is a promise. You must use `async/await` or React's [`use`](https://react.dev/reference/react/use) function to access the values. | |
| - In version 14 and earlier, `params` was a synchronous prop. To help with backwards compatibility, you can still access it synchronously in Next.js 15, but this behavior will be deprecated in the future. | |