---
url: https://lit-ui-router.dev/reference/lit-ui-router/core/requestRouter.md
---
[lit-ui-router](../index.md) / requestRouter

# Variable: requestRouter

```ts
const requestRouter: (target, options?) => UIRouterLit | undefined;
```

Defined in: [packages/lit-ui-router/src/context.ts:327](https://github.com/simshanith/lit-ui-router/blob/740888c2b2ba358c4dfa52a122e927df6a604b12/packages/lit-ui-router/src/context.ts#L327)

Requests the router from whichever provider answers on `target`, and returns
the value a provider supplied synchronously — the router instance of
[requestContext](requestContext.md).

The target is any `EventTarget`, not only an element. Returns `undefined`
when nobody answered.

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `target` | `EventTarget` | the event target to dispatch the request from |
| `options?` | [`RequestRouterOptions`](../types/RequestRouterOptions.md) | subscription and callback options |

## Returns

[`UIRouterLit`](UIRouterLit.md) | `undefined`

## Example

```ts
import { requestRouter } from 'lit-ui-router/context';
import { LitElement } from 'lit';
import type { UIRouterLit } from 'lit-ui-router';

class MyElement extends LitElement {
  router?: UIRouterLit;

  connectedCallback() {
    super.connectedCallback();
    this.router = requestRouter(this);
  }
}
```
