Unverified Commit 323ec0ae authored by Macw07's avatar Macw07 Committed by GitHub

docs: fix incorrect usage of Promise in page params example (#79804)

The documentation incorrectly used `params: Promise<{ slug: string }>`
in an example and attempted to use `await` in a non-async function.

This commit updates the example to reflect the correct usage:

- `params` should be a synchronous object: `{ slug: string }`
- The page component should be declared `async` if using `await` inside

This fixes a misleading example and aligns it with actual behavior in
the Next.js App Router: [cause]: SyntaxError: await is only valid in
async functions and the top level bodies of modules


![image](https://github.com/user-attachments/assets/6ec80f29-9a03-4006-908f-c2d9e956064a)
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 0b5196f4
...@@ -214,7 +214,7 @@ If you were to combine the two layouts above, the root layout (`app/layout.js`) ...@@ -214,7 +214,7 @@ If you were to combine the two layouts above, the root layout (`app/layout.js`)
To create a dynamic segment, wrap the segment (folder) name in square brackets: `[segmentName]`. For example, in the `app/blog/[slug]/page.tsx` route, the `[slug]` is the dynamic segment. To create a dynamic segment, wrap the segment (folder) name in square brackets: `[segmentName]`. For example, in the `app/blog/[slug]/page.tsx` route, the `[slug]` is the dynamic segment.
```tsx filename="app/blog/[slug]/page.tsx" switcher ```tsx filename="app/blog/[slug]/page.tsx" switcher
export default function BlogPostPage({ export default async function BlogPostPage({
params, params,
}: { }: {
params: Promise<{ slug: string }> params: Promise<{ slug: string }>
...@@ -232,7 +232,7 @@ export default function BlogPostPage({ ...@@ -232,7 +232,7 @@ export default function BlogPostPage({
``` ```
```jsx filename="app/blog/[slug]/page.js" switcher ```jsx filename="app/blog/[slug]/page.js" switcher
export default function BlogPostPage({ params }) { export default async function BlogPostPage({ params }) {
const { slug } = await params const { slug } = await params
const post = await getPost(slug) const post = await getPost(slug)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment