---
schema_version: "1"
id: 4390f5c47d56bb5023e4a78f4fb883647e7ffd864505b24a7fded5aafd77b5f9
title: generateUrl()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/lwr-node/lwr/references/csr-reference/generateurl.md
canonical_url: https://developer.salesforce.com/docs/platform/lwr/references/csr-reference/generateurl.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e0439b7bb2a4cbb0d9f0c14d2bedb5a91ed96acd21b43dbb7d71919a5199a648
products:
  - Lightning Web Runtime
---
# generateUrl()

Generates a URL for a specified page reference.

## Properties

| Method Input    | Type   | Required/Optional | Description                                                                                                                                                                                      |
| --------------- | ------ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `context`       | String | Required          | The ID of the parent router container nearest to the component that's generating a URL. A `ContextId` is an opaque value that you get from the [`NavigationContext`](https://developer.salesforce.com/docs/platform/lwr/references/csr-reference/navigationcontext.md) wire. |
| `pageReference` | String | Required          | The [`PageReference`](https://developer.salesforce.com/docs/platform/lwr/references/csr-reference/pagereference.md) value for which to generate a URL.                                                                                                                       |

## Syntax

```javascript
import { LightningElement, api, wire } from 'lwc';
import { NavigationContext, generateUrl } from 'lwr/navigation';
import type { ContextId, PageReference } from 'lwr/navigation';

generateUrl(
    context: ContextId,
    pageReference: PageReference
    ): string | null
```

## Returns

- If `pageReference` is valid, `generateUrl()` returns a string with the generated URL for the specified route.
- If `pageReference` is invalid, it returns `null`.
- If `context` is invalid, `generateUrl()` fails.

**See Also**

- [Simple Client-Side Routing: Navigate](https://developer.salesforce.com/docs/platform/lwr/guides/lwr-routing-example-simple.md#navigate)
