# mergePath

**Kind:** Function

**Source:** [`src/utils/url.ts`](https://github.com/honojs/hono/blob/main/src/utils/url.ts#L158)

**Part of:** [Utils](subsystem-src-utils)

Merge paths.

`mergePath` combines path values into a single URL path. Use it when building route, endpoint, or asset paths so callers do not need to concatenate path strings manually.

## Signature

```ts
function mergePath(base: string | undefined, sub: string | undefined, rest: string[]): string
```

## Parameters

| Name | Type |
|---|---|
| `base` | `string | undefined` |
| `sub` | `string | undefined` |
| `rest` | `string[]` |

**Returns:** `string`

## Diagram

```mermaid
graph LR
  A[Base path] --> C[mergePath]
  B[Path segment] --> C
  C --> D[Merged path]
```

## Usage

```ts
import { mergePath } from './utils/url';

const usersPath = mergePath('/api/', '/users');

console.log(usersPath); // /api/users
```

## AI Coding Instructions

- Pass path segments to `mergePath` instead of concatenating strings with `/`.
- Keep path inputs consistent with existing callers, especially leading and trailing slashes.
- Use this helper when constructing routes, API endpoints, or asset paths in shared URL-building code.
- Do not assume it handles full URLs, query parameters, or hash fragments unless its implementation supports them.

## Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Imported by (1)

- `HonoOptions` — `src/hono-base.ts`:46
