---
url: >-
  https://lit-ui-router.dev/api/ui-router-server/fetch/functions/delegateContext.md
---
[ui-router-server](../../index.md) / [fetch](../index.md) / delegateContext

# Function: delegateContext()

```ts
function delegateContext<K, Decls>(
   request, 
   key, 
   router?
): DelegateContext<K, Decls>;
```

Defined in: [fetch.ts:381](https://github.com/simshanith/lit-ui-router/blob/3ab90929a8d23dda96e259d7396a274c5b05398e/packages/ui-router-server/src/fetch.ts#L381)

The route a request matched when the fetch adapter delegated it to `key`'s
handler: `{ mount, subpath, delegate, state, params }`. Call it with the
very Request the handler received (`c.req.raw` in a Hono route): the
context is keyed by that object, so `request.clone()` or
`new Request(request)` has none. Pass the router to type `state` and
`params` from its `as const` routes and to check the request came through it.

## Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
|  `K` *extends* `string` | - |
|  `Decls` *extends* [`RouteDeclaration`](../../redirects/interfaces/RouteDeclaration.md) | [`RouteDeclaration`](../../redirects/interfaces/RouteDeclaration.md) |

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `request` | [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) | the request a delegate handler received |
| `key` | `K` | the delegate key the handler is mapped to |
| `router?` | [`ServerRouter`](../../index/interfaces/ServerRouter.md)<`Decls`> | the router the adapter was built with |

## Returns

[`DelegateContext`](../type-aliases/DelegateContext.md)<`K`, `Decls`>

## Throws

when the request was not delegated, was delegated to another key,
or came through another router
