buildUrl

GitHub查看源码
根据基础 URL、路径和查询参数构建完整的 URL 字符串,支持灵活的参数组合。

用法

buildUrl 函数用于构建完整 URL。

import { buildUrl } from '@movk/core'

buildUrl('https://example.com', '/api/users', { page: 1, limit: 10 })
// 'https://example.com/api/users?page=1&limit=10'

buildUrl('https://example.com', '/page', null, 'section')
// 'https://example.com/page#section'

buildUrl('https://example.com', '/api', { ids: [1, 2, 3] })
// 'https://example.com/api?ids=1&ids=2&ids=3'

API

buildUrl(base, path?, query?, hash?)

构建完整 URL。

参数

base
string required
基础 URL。
path
string
路径部分。
query
QueryParams | null
查询参数。
hash
string
哈希部分。

返回值

返回值
string
完整 URL。

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License