---
url: https://lit-ui-router.dev/api/ui-router-server/ssr/functions/redirectedTo.md
---
[ui-router-server](../../index.md) / [ssr](../index.md) / redirectedTo

# Function: redirectedTo()

```ts
function redirectedTo(router, transition): SettledRedirect | undefined;
```

Defined in: [ssr.ts:273](https://github.com/simshanith/lit-ui-router/blob/7bdd3cf0bd48783ba4e25f2357e52538c6e515f1/packages/ui-router-server/src/ssr.ts#L273)

Reports where `transition` was redirected to, so a host answers the
request with a redirect instead of the page it landed on. A transition is
redirected when a `redirectTo`, data or function, or a hook returning a
target state moved it, a change of params alone included. The status is
the `redirectStatusCode` of the state the redirect chain started from, the
state the url matched.

A url rule that rewrites the url (`when('/old', '/new')`) starts a fresh
transition rather than redirecting one, so it reports nothing: the
verdict answers a mount's pattern rules before render. A redirect with
`location: false` leaves the url where it was and reports nothing either.

Call it with the transition `settle` resolved. On a router that serves
more than one path, `settle` on the path the router already stands on
resolves with the transition that brought it there, which may be an
earlier path's redirect.

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `router` | [`UIRouter`](https://ui-router.github.io/core/docs/latest/classes/_router_.uirouter.html) | the router `transition` ran on, read for the url it landed on |
| `transition` | [`Transition`](https://ui-router.github.io/core/docs/latest/classes/_transition_transition_.transition.html) | the transition `settle` resolved with |

## Returns

[`SettledRedirect`](../interfaces/SettledRedirect.md) | `undefined`

the landed url and status, or `undefined` when nothing redirected it

## Example

```ts
import { redirectedTo, settle } from 'ui-router-server/ssr';

// `router` serves the mount at /releases; `subpath` is the request's path within it.
const redirect = redirectedTo(router, await settle(router, subpath));

if (redirect)
  return new Response(null, {
    status: redirect.status,
    headers: { Location: `/releases${redirect.url}` },
  });
```
