Skip to content

Commit

Permalink
docs: update Route Handlers to have JS/TS code snippet. (#51003)
Browse files Browse the repository at this point in the history
Added a TS and JS switcher. Previously the code snippet did not have a
switcher. The file extension was .js when the code was TypeScript which
made it confusing to try to read.

---------

Co-authored-by: Lee Robinson <me@leerob.io>
  • Loading branch information
thepatrick00 and leerob committed Jun 9, 2023
1 parent cdd366f commit 3817770
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,19 +365,21 @@ export async function GET(request) {
Route Handlers can use [Dynamic Segments](/docs/app/building-your-application/routing/dynamic-routes) to create request handlers from dynamic data.

```ts filename="app/items/[slug]/route.js"
```ts filename="app/items/[slug]/route.ts" switcher
export async function GET(
request: Request,
{
params,
}: {
params: { slug: string }
}
{ params }: { params: { slug: string } }
) {
const slug = params.slug // 'a', 'b', or 'c'
}
```

```js filename="app/items/[slug]/route.js" switcher
export async function GET(request, { params }) {
const slug = params.slug // 'a', 'b', or 'c'
}
```

| Route | Example URL | `params` |
| --------------------------- | ----------- | --------------- |
| `app/items/[slug]/route.js` | `/items/a` | `{ slug: 'a' }` |
Expand Down

0 comments on commit 3817770

Please sign in to comment.