diff --git a/docs/2.guide/2.directory-structure/1.server.md b/docs/2.guide/2.directory-structure/1.server.md index 26fcf891d7..55b10d5747 100644 --- a/docs/2.guide/2.directory-structure/1.server.md +++ b/docs/2.guide/2.directory-structure/1.server.md @@ -152,7 +152,10 @@ Server routes can use dynamic parameters within brackets in the file name like ` **Example:** ```ts [server/api/hello/[name\\].ts] -export default defineEventHandler((event) => `Hello, ${event.context.params.name}!`) +export default defineEventHandler((event) => { + const name = getRouterParam(event, 'name') + return `Hello, ${name}!` +}) ``` You can now universally call this API using `await $fetch('/api/hello/nuxt')` and get `Hello, nuxt!`.