这个模块含有一些系列方法函数处理和解析URL
使用require('url')
使用浏览器
这个方法返回包含具体路由信息的对象
没有就返回null函数
url.parse('http://user:pass@host.com:8080/p/a/t/h?query=string') { protocol: 'http:', slashes: true, auth: 'user:pass', host: 'host.com:8080', port: '8080', hostname: 'host.com', hash: null, search: '?query=string', query: 'query=string', pathname: '/p/a/t/h', path: '/p/a/t/h?query=string', href: 'http://user:pass@host.com:8080/p/a/t/h?query=string#hash' }
href,完整的路径ui
pathname,路径名字不包含参数url
host比hostname多一个端口号code
同理这个函数就是根据obj的信息构造一个路径orm
var obj = { protocol: 'https', host: 'www.cycok.com:4000', pathname: 'index' } url.format(obj) //returns 'https://www.cycok.com:4000/index'
提供一个基础的路径,还有要去的路径,解析出浏览器最终会去的路径对象
url.resolve('/one/two/three', 'four') // '/one/two/four' url.resolve('http://example.com/', '/one') // 'http://example.com/one' url.resolve('http://example.com/one', '/two') // 'http://example.com/two'