---
schema_version: "1"
id: dc9ea10079a447a581fca991e3d2a34df6cbfdee2049dc357d2ff4a11141b803
title: createRouter()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/lwr-node/lwr/references/csr-reference/createrouter.md
canonical_url: https://developer.salesforce.com/docs/platform/lwr/references/csr-reference/createrouter.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 354efca182975965581f41aeb2d79481699348e75d7f6d6f486159bd500dead6
products:
  - Lightning Web Runtime
---
# createRouter()

Creates and initializes an LWR router.

## Properties

| Method Input | Type                  | Required/Optional | Description                                                                                                                                                            |
| ------------ | --------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `config`     | `RouterConfig` object | Optional          | Pass in the [`RouterConfig`](https://developer.salesforce.com/docs/platform/lwr/references/csr-reference/routerconfig.md) object you want to create a router for. If you don't specify a `RouterConfig`, LWR creates a router with default values. |

**note:** We recommend that you specify a `RouterConfig` for `createRouter()`. If you don't pass in a value for `RouterConfig.routes`, the router can't match any locations.

## Syntax

```javascript
import { createRouter } from 'lwr/router';

createRouter(config?: RouterConfig
    ): Router<PageReference>
```

## Returns

- A router object that you can pass to a [router container component](https://developer.salesforce.com/docs/platform/lwr/references/csr-reference/lwr-router-container.md).

**See Also**

- [Create a Router: createRouter()](https://developer.salesforce.com/docs/platform/lwr/guides/lwr-create-router.md#createrouter)
- [Routers and Route Matching](https://developer.salesforce.com/docs/platform/lwr/guides/lwr-routers-route-matching.md)
- [Simple Client-Side Routing](https://developer.salesforce.com/docs/platform/lwr/guides/lwr-routing-example-simple.md#create-a-router)
