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
|
|
|
|
|
|
|
Within your pages, components, and plugins you can use `useRequestEvent` to access the incoming request.
|
|
|
|
|
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
|
2023-08-23 07:30:53 +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`.
|
|
|
|
::
|