buildUrl

用于构建包含查询参数的 URL 的辅助函数。


const url = drupal.buildUrl(path, params?): URL
  • path: string
    • 必需
    • URL 的路径。例如:"/example"
  • params: string | Record<string, string> | URLSearchParams | JsonApiParams
    • 可选

示例

const drupal = new DrupalClient("https://example.com")
// https://drupal.org
drupal.buildUrl("https://drupal.org").toString()
// https://example.com/foo
drupal.buildUrl("/foo").toString()
// https://example.com/foo?bar=baz
client.buildUrl("/foo", { bar: "baz" }).toString()
  • DrupalJsonApiParams 构建 URL
const params = {
getQueryObject: () => ({
sort: "-created",
"fields[node--article]": "title,path",
}),
}
// https://example.com/jsonapi/node/article?sort=-created&fields%5Bnode--article%5D=title%2Cpath
drupal.buildUrl("/jsonapi/node/article", params).toString()