Unverified Commit 3817770b authored by PatrickCodes_'s avatar PatrickCodes_ Committed by GitHub

docs: update Route Handlers to have JS/TS code snippet. (#51003)

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: 's avatarLee Robinson <me@leerob.io>
parent cdd366fd
...@@ -365,19 +365,21 @@ export async function GET(request) { ...@@ -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. 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( export async function GET(
request: Request, request: Request,
{ { params }: { params: { slug: string } }
params,
}: {
params: { slug: string }
}
) { ) {
const slug = params.slug // 'a', 'b', or 'c' 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` | | Route | Example URL | `params` |
| --------------------------- | ----------- | --------------- | | --------------------------- | ----------- | --------------- |
| `app/items/[slug]/route.js` | `/items/a` | `{ slug: 'a' }` | | `app/items/[slug]/route.js` | `/items/a` | `{ slug: 'a' }` |
......
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