url.pathname


获取和设置网址的路径部分。

【Gets and sets the path portion of the URL.】

const myURL = new URL('https://example.org/abc/xyz?123');
console.log(myURL.pathname);
// Prints /abc/xyz

myURL.pathname = '/abcdef';
console.log(myURL.href);
// Prints https://example.org/abcdef?123 

分配给 pathname 属性的值中包含无效的 URL 字符是 百分比编码。选择对哪些字符进行百分比编码可能与 url.parse()url.format() 方法产生的结果略有不同。

【Invalid URL characters included in the value assigned to the pathname property are percent-encoded. The selection of which characters to percent-encode may vary somewhat from what the url.parse() and url.format() methods would produce.】