nodejs 中 url.parse().pathname 这个 pathname 是什么呢? 函数?属性?方法?

2017-08-08 23:43:13 +08:00
 supman
4555 次点击
所在节点    问与答
7 条回复
imcj
2017-08-08 23:53:56 +08:00
文档看过了?
supman
2017-08-09 00:00:47 +08:00
@imcj 本来木有看。。直接看的在线教程 https://www.nodebeginner.org

不过问这个问题之前 也搜索了下文档 https://nodejs.org/api/url.html#url_url_pathname 介绍了这个东西的用途 但并没有说明这是个什么东东。。
orzfly
2017-08-09 00:22:47 +08:00
属性。url.parse("...") 的返回是一个对象,pathname 是这个对象的一个属性。

```
orzfly@mirai:~$ irb
irb(main):001:0> url.parse()^C
irb(main):001:0> exit
orzfly@mirai:~$ node
> url.parse("https://www.v2ex.com/t/381509#reply2")
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'www.v2ex.com',
port: null,
hostname: 'www.v2ex.com',
hash: '#reply2',
search: null,
query: null,
pathname: '/t/381509',
path: '/t/381509',
href: 'https://www.v2ex.com/t/381509#reply2' }
>
(To exit, press ^C again or type .exit)
>
```
lzhr
2017-08-09 00:39:29 +08:00
https://nodejs.org/api/url.html#url_url_strings_and_url_objects
Below it are properties of a WHATWG URL object.
Trim21
2017-08-09 01:40:17 +08:00
楼上的图不错。。搭车问一下有没有什么类似的生成工具?
imcj
2017-08-09 08:12:14 +08:00
@supman @lzr 正解

刚复制的

const { URL } = require('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
SourceMan
2017-08-09 08:50:41 +08:00
这个叫 构成

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/381509

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX