# @dreamworld/router

> It parses current URL and provides navigation methods.

Latest version **3.2.0** (published 2025-08-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install @dreamworld/router
pnpm add @dreamworld/router
yarn add @dreamworld/router
bun add @dreamworld/router
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2025-08-07 |
| First published | 2021-09-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 44.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ruchita kheni |
| Maintainers | chiragmoradiya, chetang7, ajay-dhameliya, dw-devops |
| Keywords | lit, input |

## Links

- npm: https://www.npmjs.com/package/@dreamworld/router
- Repository: https://github.com/DreamworldSolutions/router
- Homepage: https://github.com/DreamworldSolutions/router#readme
- Issues: https://github.com/DreamworldSolutions/router/issues
- npm.io page: https://npm.io/package/@dreamworld/router

## Dependencies (4)

- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.15
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.2.0
- [query-string-esm](https://npm.io/package/query-string-esm.md) ^6.13.6
- [@dreamworld/pwa-helpers](https://npm.io/package/@dreamworld/pwa-helpers.md) ^1.16.0

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 3.2.0 (latest) — 2025-08-07
- 3.2.1-migrate-circleci-to-github-actions.1 (migrate-circleci-to-github-actions) — 2026-11-16
- 3.0.1-support-query-params-data-type.1 (support-query-params-data-type) — 2023-04-24
- 2.3.0-ssr.2 (ssr) — 2023-02-20
- 2.1.0-add-type-module.1 (add-type-module) — 2023-02-14
- 2.0.0-upgrade-to-lit.1 (upgrade-to-lit) — 2022-10-07
- 1.0.0-init.2 (init) — 2021-09-15
- 3.1.0 — 2024-08-08
- 3.0.2 — 2023-06-13
- 3.0.1 — 2023-04-24
- 3.0.0 — 2023-04-19
- 2.3.2 — 2023-04-18
- 2.4.0-support-query-params-data-type.1 — 2023-04-05
- 2.3.1 — 2023-03-05
- 2.3.0 — 2023-02-21
- … 6 more at https://npm.io/package/@dreamworld/router/versions

## README

# Router

## Behaviors

- Parses the current URL to the redux state.
- Provides public methods for the page/dialog navigation.
- Handles Anchor Tag navigation.

## Usage pattern

```js
import { init, registerFallbackCallback } from '@dreamworld/router';

// init routing flow
init(URLs, store);

// Register fallback callback
registerFallbackCallback(callback)

// Exports all the methods provides by the router module
export * from '@dreamworld/router'; 
```

### URLs: format of the URLs

This Object contains all page/dialog Urls of the application. format is as below:

```js
URLs = {
  pages: [{
    module: 'contacts',
    name: 'contact-list',
    pathPattern: '/:companyId/contacts',
    pathParams: {
      companyId: Number
    },
    queryParams: {
      s: {
        name: "size",
        type: String //Boolean, Number
      },
      ids: {
        name:: "docIds",
        type: String,
        array: true
      }
    },
    arrayFormat: "separator" //It will override default global config
    arrayFormatSeparator: "|"
  }],

  dialogs: [{
    name: 'contact-view',
    pathPattern: '#contact-view',
    queryParams: {}
  }]
}
```

**Notes**
- When `array=true`, `type` specified type of an array element.
- As default value of `type` is `String`, when `type` isn't defined for `queryParams`, then it always parse as `String`. If `array: true` isn't specified and queryParam's value is comma separated then it would be parsed as `String`. 

- To make path parameter optional use `?`.  e.g. `/:companyId/contact/:tab?`.

- All the keys except `pathPattern`, `pathParams`, `queryParams` will be provided as it is in the parsed object.

- Provide comma separated value in query params to parse it as `Array`. e.g `ids=1,2,3,4`

- It will parse query params in related data type.
    - e.g. URL params is `?action=edit&ids=d64bd8f3ef4463d048963790dcf53193,8b0397b832e9d654e67fa3a5e6935d16&archived=true&count=2`.
      - parsed object of above params is as below:
        ```json
        {
          "action":"edit",
          "ids":["d64bd8f3ef4463d048963790dcf53193","8b0397b832e9d654e67fa3a5e6935d16"],
          "archived":true,
          "count":2
        }
        ```

## State
Path: `/router`


| Name               | Type | description |
|--------------------|-----------|-------------|
| page.name          | String    | Name of the internal Page of module to be used in the module's logic/routing. | 
| page.params        | Object     | Parameters of the page. This is dynamic object constructed from the path params and query params. Exact parameters are dependent on the page. |
| page.module          | String    | Name of the app module to be used in the app's logic/routing | 
| dialog.name          | String    | Name of the dialog to be used in the application's logic/routing. | 
| dialog.params        | Object     | Parameters of the page. This is dynamic object constructed from the path params and query params. Exact parameters are dependent on the dialog.

## Methods

- `init (urls, store)` // Used to intialize routing flow
- `navigate (url, bReplace)` // Use to navigate on given URL
- `back()` // Use to navigate on previous page
- `registerFallbackCallback (callback)` // Use to register fallback function for `back` action.
- `setDefaultArrayFormat (format, separator)` // Use to set default arrayFormat config. Default: `arrayFormat: comma`
- For page
  - `navigatePage (pageName, pageParams, replace = false)` // Used to navigate on given page name
  - `setPageParams (pageParams, replace)` // Used to update current URL's params
  - `buildPageURL (pageName, pageParams)` // Used to get given page URL
- For dialog
  - `navigateDialog (dialogName, dialogParams, replace = false)` // Used to navigate on the given dialog name
  - `setDialogParams (dialogParams, replace)` // Used to set params in the current hash
  - `buildDialogURL (dialogName, dialogParams)` // Used to get dialog URL

---
_Source: https://npm.io/package/@dreamworld/router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
