# urls.JoinPath
> 把给定的元素拼接成一个 URL 字符串，并清理结果中的 ./ 与 ../ 元素；参数列表为空时返回空字符串。
- 官方英文原文：https://gohugo.io/functions/urls/joinpath/
- 本页规范地址：https://hugozh.cn/functions/urls/joinpath/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：urls.JoinPath ELEMENT...
- 返回类型：string
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
```go-html-template
{{ urls.JoinPath }} → "" (empty string)
{{ urls.JoinPath "" }} → /
{{ urls.JoinPath "a" }} → a
{{ urls.JoinPath "a" "b" }} → a/b
{{ urls.JoinPath "/a" "b" }} → /a/b
{{ urls.JoinPath "https://example.org" "b" }} → https://example.org/b

{{ urls.JoinPath (slice "a" "b") }} → a/b
```

与 [`path.Join`][] 函数不同，`urls.JoinPath` 会保留开头连续的斜杠。

[`path.Join`]: /functions/path/join/

