2022-10-06 09:15:30 +00:00
|
|
|
---
|
2023-10-18 10:59:43 +00:00
|
|
|
title: 'useRequestEvent'
|
|
|
|
description: 'Access the incoming request event with the useRequestEvent composable.'
|
|
|
|
links:
|
|
|
|
- label: Source
|
|
|
|
icon: i-simple-icons-github
|
|
|
|
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts
|
|
|
|
size: xs
|
2022-10-06 09:15:30 +00:00
|
|
|
---
|
2022-06-09 11:07:28 +00:00
|
|
|
|
2024-01-31 09:46:21 +00:00
|
|
|
Within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context) you can use `useRequestEvent` to access the incoming request.
|
2022-06-09 11:07:28 +00:00
|
|
|
|
2023-10-18 10:59:43 +00:00
|
|
|
```ts
|
2022-06-09 11:07:28 +00:00
|
|
|
// Get underlying request event
|
|
|
|
const event = useRequestEvent()
|
|
|
|
|
|
|
|
// Get the URL
|
2024-01-29 11:48:35 +00:00
|
|
|
const url = event?.path
|
2022-06-09 11:07:28 +00:00
|
|
|
```
|
|
|
|
|
2023-10-18 10:59:43 +00:00
|
|
|
::callout
|
2022-06-09 11:07:28 +00:00
|
|
|
In the browser, `useRequestEvent` will return `undefined`.
|
|
|
|
::
|